ZQuest Classic Coverage Report


Directory: src/
File: src/zc/maps.cpp
Date: 2025-07-14 08:59:54
Exec Total Coverage
Lines: 4072 5061 80.5%
Functions: 279 320 87.2%
Branches: 3159 5107 61.9%

Line Branch Exec Source
1 #include "base/combo.h"
2 #include "base/handles.h"
3 #include "base/util.h"
4 #include "base/zdefs.h"
5 #include "base/general.h"
6 #include <cstring>
7 #include <assert.h>
8 #include <math.h>
9 #include <vector>
10 #include <deque>
11 #include <string>
12 #include <set>
13 #include <array>
14 #include <sstream>
15 using std::set;
16
17 #include "base/qrs.h"
18 #include "base/dmap.h"
19 #include "base/mapscr.h"
20 #include "base/misctypes.h"
21 #include "base/initdata.h"
22 #include "zc/maps.h"
23 #include "zc/zelda.h"
24 #include "zc/zc_ffc.h"
25 #include "tiles.h"
26 #include "sprite.h"
27 #include "gui/jwin.h"
28 #include "base/zsys.h"
29 #include "subscr.h"
30 #include "zc/zc_subscr.h"
31 #include "zc/hero.h"
32 #include "zc/guys.h"
33 #include "zc/ffscript.h"
34 #include "drawing.h"
35 #include "zc/combos.h"
36 #include "zc/replay.h"
37 #include "slopes.h"
38 #include "particles.h"
39 #include <fmt/format.h>
40 #include "zc/render.h"
41 #include "iter.h"
42 #include <ranges>
43
44 // All the temporary screens (and their layers) for the currently loaded map.
45 static mapscr* temporary_screens[136*7];
46 // Set by load_region.
47 static bool screen_in_current_region[136];
48 408 static rpos_handle_t current_region_rpos_handles[136*7];
49 static bool current_region_rpos_handles_dirty;
50 static int current_region_screen_count;
51 static std::pair<const rpos_handle_t*, int> current_region_rpos_handles_scr[136];
52
53 viewport_t viewport;
54 static int viewport_sprite_uid;
55 ViewportMode viewport_mode;
56 int world_w, world_h;
57 int region_scr_dx, region_scr_dy;
58 int region_scr_count;
59 rpos_t region_max_rpos;
60 int region_num_rpos;
61 region_t cur_region, scrolling_region;
62
63 408 maze_state_t maze_state;
64 int scrolling_maze_last_solved_screen;
65
66 573 void maps_init_game_vars()
67 {
68 573 viewport = {};
69 573 viewport_mode = ViewportMode::CenterAndBound;
70 573 viewport_sprite_uid = 1;
71 573 currscr_for_passive_subscr = -1;
72 573 }
73
74 static region_ids_t current_region_ids;
75
76 14559383 static bool is_a_region(int map, int scr)
77 {
78 14559383 return get_region_id(map, scr) != 0;
79 }
80
81 2232 static bool is_same_region_id(int region_origin_scr, int map, int scr)
82 {
83
2/2
✓ Branch 0 taken 772 times.
✓ Branch 1 taken 1460 times.
2232 if (!is_a_region(map, scr)) return false;
84 1460 int region_id = get_region_id(map, region_origin_scr);
85
1/2
✓ Branch 0 taken 1460 times.
✗ Branch 1 not taken.
1460 return region_id && region_id == get_region_id(map, scr);
86 2232 }
87
88 138234084 bool is_in_current_region(int map, int screen)
89 {
90
5/6
✓ Branch 0 taken 138232511 times.
✓ Branch 1 taken 1573 times.
✓ Branch 2 taken 138232511 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12213 times.
✓ Branch 5 taken 138220298 times.
138234084 return map == cur_map && screen >= 0 && screen < 128 && screen_in_current_region[screen];
91 }
92
93 69622285 bool is_in_current_region(int screen)
94 {
95
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 69622284 times.
69622285 return screen < 128 && screen_in_current_region[screen];
96 }
97
98 28943214 bool is_in_current_region(mapscr* scr)
99 {
100
4/4
✓ Branch 0 taken 28928193 times.
✓ Branch 1 taken 15021 times.
✓ Branch 2 taken 459339 times.
✓ Branch 3 taken 28468854 times.
28943214 return scr->map == cur_map && scr->screen < 128 && screen_in_current_region[scr->screen];
101 }
102
103 bool is_in_scrolling_region(int screen)
104 {
105 if (!screenscrolling) return false;
106
107 int x = screen % 16;
108 int y = screen / 16;
109 return
110 scrolling_region.origin_screen_x >= x && scrolling_region.origin_screen_x < x + scrolling_region.screen_width &&
111 scrolling_region.origin_screen_y >= y && scrolling_region.origin_screen_y < y + scrolling_region.screen_height;
112 }
113
114 8983711040 bool is_in_scrolling_region()
115 {
116 8983711040 return cur_region.screen_count > 1;
117 }
118
119 76530576 bool is_extended_height_mode()
120 {
121
2/2
✓ Branch 0 taken 76280442 times.
✓ Branch 1 taken 250134 times.
76530576 return cur_region.screen_height > 1 && (DMaps[cur_dmap].flags & dmfEXTENDEDVIEWPORT);
122 }
123
124 // Returns 0 if this is not a region.
125 15601255 int get_region_id(int map, int screen)
126 {
127
2/2
✓ Branch 0 taken 398643 times.
✓ Branch 1 taken 15202612 times.
15601255 if (screen >= 128) return 0;
128
2/2
✓ Branch 0 taken 15201512 times.
✓ Branch 1 taken 1100 times.
15202612 if (map == cur_region.map) return current_region_ids[screen];
129
130 1100 return Regions[map].get_region_id(screen);
131 15601255 }
132
133 982758 int get_current_region_id()
134 {
135 982758 return get_region_id(cur_map, cur_screen);
136 }
137
138 64033 void calculate_region(int map, int screen, region_t& region, int& region_scr_dx, int& region_scr_dy)
139 {
140 64033 region.map = map;
141
142
3/4
✓ Branch 0 taken 274 times.
✓ Branch 1 taken 63759 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 274 times.
64033 if (!(is_a_region(map, screen)) || screen >= 0x80)
143 {
144 63759 region.region_id = 0;
145 63759 region.origin_screen = screen;
146 63759 region.origin_screen_x = screen % 16;
147 63759 region.origin_screen_y = screen / 16;
148 63759 region.screen_width = 1;
149 63759 region.screen_height = 1;
150 63759 region.screen_count = 1;
151 63759 region.width = 256;
152 63759 region.height = 176;
153 63759 region_scr_dx = 0;
154 63759 region_scr_dy = 0;
155 63759 return;
156 }
157
158 274 int input_scr_x = screen % 16;
159 274 int input_scr_y = screen / 16;
160
161 // For the given screen, find the top-left corner of its region.
162 274 int origin_scr_x = input_scr_x;
163 274 int origin_scr_y = input_scr_y;
164 274 int origin_scr = screen;
165
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 372 times.
434 while (origin_scr_x > 0)
166 {
167
2/2
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 160 times.
372 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x - 1, origin_scr_y))) break;
168 160 origin_scr_x--;
169 }
170
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 414 times.
508 while (origin_scr_y > 0)
171 {
172
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 234 times.
414 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x, origin_scr_y - 1))) break;
173 234 origin_scr_y--;
174 }
175 274 origin_scr = map_scr_xy_to_index(origin_scr_x, origin_scr_y);
176
177 // Now find the bottom-right corner.
178 274 int region_scr_right = origin_scr_x;
179
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 614 times.
642 while (region_scr_right < 15)
180 {
181
2/2
✓ Branch 0 taken 246 times.
✓ Branch 1 taken 368 times.
614 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(region_scr_right + 1, origin_scr_y))) break;
182 368 region_scr_right++;
183 }
184 274 int region_scr_bottom = origin_scr_y;
185
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 832 times.
856 while (region_scr_bottom < 7)
186 {
187
2/2
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 582 times.
832 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x, region_scr_bottom + 1))) break;
188 582 region_scr_bottom++;
189 }
190
191 274 region.region_id = get_region_id(map, origin_scr);
192 274 region.origin_screen = origin_scr;
193 274 region.origin_screen_x = origin_scr_x;
194 274 region.origin_screen_y = origin_scr_y;
195 274 region.screen_width = region_scr_right - origin_scr_x + 1;
196 274 region.screen_height = region_scr_bottom - origin_scr_y + 1;
197 274 region.screen_count = region.screen_width * region.screen_height;
198 274 region.width = 256 * region.screen_width;
199 274 region.height = 176 * region.screen_height;
200 274 region_scr_dx = input_scr_x - origin_scr_x;
201 274 region_scr_dy = input_scr_y - origin_scr_y;
202
203 DCHECK_RANGE_INCLUSIVE(region.screen_width, 0, 16);
204 DCHECK_RANGE_INCLUSIVE(region.screen_height, 0, 8);
205 64033 }
206
207 35756 void load_region(int dmap, int screen)
208 {
209 35756 clear_temporary_screens();
210
211 35756 int map = DMaps[dmap].map;
212 35756 current_region_ids = Regions[map].get_all_region_ids();
213
214 35756 calculate_region(map, screen, cur_region, region_scr_dx, region_scr_dy);
215 35756 cur_screen = cur_region.origin_screen;
216 35756 world_w = cur_region.width;
217 35756 world_h = cur_region.height;
218 35756 region_scr_count = cur_region.screen_count;
219 35756 region_max_rpos = (rpos_t)(cur_region.screen_count*176 - 1);
220 35756 region_num_rpos = cur_region.screen_count*176;
221 35756 scrolling_maze_last_solved_screen = 0;
222
223 35756 memset(screen_in_current_region, false, sizeof(screen_in_current_region));
224
2/2
✓ Branch 0 taken 35990 times.
✓ Branch 1 taken 35756 times.
71746 for (int x = 0; x < cur_region.screen_width; x++)
225 {
226
2/2
✓ Branch 0 taken 37000 times.
✓ Branch 1 taken 35990 times.
72990 for (int y = 0; y < cur_region.screen_height; y++)
227 {
228 37000 int screen = cur_screen + x + y*16;
229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37000 times.
37000 if (screen < 136)
230 {
231 37000 screen_in_current_region[screen] = true;
232 37000 }
233 37000 }
234 35990 }
235
236 35756 mark_current_region_handles_dirty();
237 35756 }
238
239 35756 static void prepare_current_region_handles()
240 {
241 35756 current_region_rpos_handles_dirty = false;
242 35756 current_region_screen_count = 0;
243
2/2
✓ Branch 0 taken 36104 times.
✓ Branch 1 taken 35756 times.
71860 for (int y = 0; y < cur_region.screen_height; y++)
244 {
245
2/2
✓ Branch 0 taken 37000 times.
✓ Branch 1 taken 36104 times.
73104 for (int x = 0; x < cur_region.screen_width; x++)
246 {
247 37000 int screen = cur_screen + x + y*16;
248 37000 int index_start = current_region_screen_count;
249
2/2
✓ Branch 0 taken 37000 times.
✓ Branch 1 taken 259000 times.
296000 for (int layer = 0; layer <= 6; layer++)
250 {
251 259000 mapscr* scr = get_scr_layer(screen, layer);
252
2/2
✓ Branch 0 taken 84338 times.
✓ Branch 1 taken 174662 times.
259000 if (!scr->is_valid())
253 {
254
1/2
✓ Branch 0 taken 174662 times.
✗ Branch 1 not taken.
174662 if (layer == 0) break;
255 174662 continue;
256 }
257
258 84338 rpos_t base_rpos = POS_TO_RPOS(0, get_region_relative_dx(screen), get_region_relative_dy(screen));
259 84338 current_region_rpos_handles[current_region_screen_count] = {scr, screen, layer, base_rpos, 0};
260 84338 current_region_screen_count += 1;
261 84338 }
262
263 37000 int num_handles_for_scr = current_region_screen_count - index_start;
264 37000 current_region_rpos_handles_scr[screen] = {&current_region_rpos_handles[index_start], num_handles_for_scr};
265 37000 }
266 36104 }
267 35756 }
268
269 1774133329 std::tuple<const rpos_handle_t*, int> get_current_region_handles()
270 {
271 DCHECK(!current_region_rpos_handles_dirty);
272 1774133329 return {current_region_rpos_handles, current_region_screen_count};
273 }
274
275 11046924 std::tuple<const rpos_handle_t*, int> get_current_region_handles(mapscr* scr)
276 {
277 DCHECK(!current_region_rpos_handles_dirty);
278
2/4
✓ Branch 0 taken 11046924 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11046924 times.
11046924 if (scr == special_warp_return_scr || current_region_rpos_handles_dirty)
279 return {nullptr, 0};
280
281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11046924 times.
11046924 if (cur_screen >= 0x80)
282 {
283 DCHECK(scr == origin_scr);
284 return {nullptr, 0};
285 }
286
287 DCHECK(is_in_current_region(scr));
288 11046924 return current_region_rpos_handles_scr[scr->screen];
289 11046924 }
290
291 35756 void mark_current_region_handles_dirty()
292 {
293 35756 current_region_rpos_handles_dirty = true;
294 35756 }
295
296 36890 void clear_temporary_screens()
297 {
298
2/2
✓ Branch 0 taken 35119280 times.
✓ Branch 1 taken 36890 times.
35156170 for (int i = 0; i < 136*7; i++)
299 {
300
2/2
✓ Branch 0 taken 35064722 times.
✓ Branch 1 taken 54558 times.
35119280 if (temporary_screens[i])
301 {
302 54558 free(temporary_screens[i]);
303 54558 temporary_screens[i] = NULL;
304 54558 }
305 35119280 }
306
307 36890 origin_scr = nullptr;
308 36890 hero_scr = nullptr;
309 36890 }
310
311 27869 std::vector<mapscr*> take_temporary_scrs()
312 {
313
1/2
✓ Branch 0 taken 27869 times.
✗ Branch 1 not taken.
27869 std::vector<mapscr*> screens(temporary_screens, temporary_screens + 136*7);
314
2/2
✓ Branch 0 taken 27869 times.
✓ Branch 1 taken 26531288 times.
26559157 for (int i = 0; i < 136*7; i++)
315 26531288 temporary_screens[i] = nullptr;
316
317 27869 return screens;
318
1/2
✓ Branch 0 taken 27869 times.
✗ Branch 1 not taken.
27869 }
319
320 14493478 void calculate_viewport(viewport_t& viewport, int dmap, int screen, int world_w, int world_h, int x, int y)
321 {
322 // TODO: In future, maybe add x/y centering offsets to zscript (Viewport->TargetXOffset/Viewport->TargetYOffset).
323
324
2/2
✓ Branch 0 taken 14446896 times.
✓ Branch 1 taken 46582 times.
14493478 bool extended_height_mode = (DMaps[dmap].flags & dmfEXTENDEDVIEWPORT) && world_h > 176;
325 14493478 viewport.w = 256;
326 14493478 viewport.h = 176 + (extended_height_mode ? 56 : 0);
327
328
2/2
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 14493118 times.
14493478 if (viewport_mode == ViewportMode::Script)
329 360 return;
330
331
2/2
✓ Branch 0 taken 46162 times.
✓ Branch 1 taken 14446956 times.
14493118 if (!is_a_region(DMaps[dmap].map, screen))
332 {
333 14446956 viewport.x = 0;
334 14446956 viewport.y = 0;
335 14446956 }
336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46162 times.
46162 else if (viewport_mode == ViewportMode::CenterAndBound)
337 {
338 // Clamp the viewport to the edges of the region.
339
6/6
✓ Branch 0 taken 8568 times.
✓ Branch 1 taken 37594 times.
✓ Branch 2 taken 6788 times.
✓ Branch 3 taken 39374 times.
✓ Branch 4 taken 8568 times.
✓ Branch 5 taken 30806 times.
46162 viewport.x = CLAMP(0, world_w - viewport.w, x - viewport.w/2);
340
6/6
✓ Branch 0 taken 11856 times.
✓ Branch 1 taken 34306 times.
✓ Branch 2 taken 5650 times.
✓ Branch 3 taken 40512 times.
✓ Branch 4 taken 11856 times.
✓ Branch 5 taken 28656 times.
46162 viewport.y = CLAMP(0, world_h - viewport.h, y - viewport.h/2);
341 46162 }
342 else if (viewport_mode == ViewportMode::Center)
343 {
344 viewport.x = x - viewport.w/2;
345 viewport.y = y - viewport.h/2;
346 }
347 14493478 }
348
349 14492967 sprite* get_viewport_sprite()
350 {
351 14492967 sprite* spr = sprite::getByUID(viewport_sprite_uid);
352
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 14492961 times.
14492967 if (!spr)
353 {
354 6 viewport_sprite_uid = 1; // Hero uid.
355 6 spr = &Hero;
356 6 }
357
358 14492967 return spr;
359 }
360
361 6 void set_viewport_sprite(sprite* spr)
362 {
363 6 viewport_sprite_uid = spr->uid;
364 6 }
365
366 14465098 void update_viewport()
367 {
368 14465098 sprite* spr = get_viewport_sprite();
369 14465098 int x = spr->x + spr->txsz*16/2;
370 14465098 int y = spr->y + spr->tysz*16/2;
371 14465098 calculate_viewport(viewport, cur_dmap, cur_screen, world_w, world_h, x, y);
372 14465098 }
373
374 14254093 void update_heroscr()
375 {
376 void playLevelMusic();
377
378 14254093 int x = vbound(Hero.getX().getInt(), 0, world_w - 1);
379 14254093 int y = vbound(Hero.getY().getInt(), 0, world_h - 1);
380 14254093 int dx = x / 256;
381 14254093 int dy = y / 176;
382 14254093 int new_screen = cur_screen + dx + dy * 16;
383
2/2
✓ Branch 0 taken 14246331 times.
✓ Branch 1 taken 7762 times.
14254093 if (maze_state.active == 1)
384 7762 new_screen = maze_state.scr->screen;
385
7/12
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 14253877 times.
✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 216 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 216 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 216 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 216 times.
14254093 if (hero_screen != new_screen && dx >= 0 && dy >= 0 && dx < 16 && dy < 8 && is_in_current_region(new_screen))
386 {
387 216 region_scr_dx = dx;
388 216 region_scr_dy = dy;
389 216 hero_screen = new_screen;
390 216 prev_hero_scr = hero_scr;
391 216 hero_scr = get_scr(hero_screen);
392 216 Hero.screen_spawned = hero_screen;
393 216 playLevelMusic();
394 216 }
395
1/2
✓ Branch 0 taken 14254093 times.
✗ Branch 1 not taken.
14254093 if (game->get_regionmapping() == REGION_MAPPING_PHYSICAL)
396 mark_visited(new_screen); // Mark each screen the hero steps foot in as visited
397 14254093 }
398
399 4722 mapscr* determine_hero_screen_from_coords()
400 {
401 4722 int x = vbound(Hero.getX().getInt(), 0, world_w - 1);
402 4722 int y = vbound(Hero.getY().getInt(), 0, world_h - 1);
403 4722 int dx = x / 256;
404 4722 int dy = y / 176;
405 4722 return get_scr(cur_screen + dx + dy * 16);
406 }
407
408 26839 bool edge_of_region(direction dir)
409 {
410
2/2
✓ Branch 0 taken 26759 times.
✓ Branch 1 taken 80 times.
26839 if (!is_in_scrolling_region()) return true;
411
412 80 int screen_x = hero_screen % 16;
413 80 int screen_y = hero_screen / 16;
414
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 2 times.
80 if (dir == up) screen_y -= 1;
415
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 10 times.
80 if (dir == down) screen_y += 1;
416
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 30 times.
80 if (dir == left) screen_x -= 1;
417
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 38 times.
80 if (dir == right) screen_x += 1;
418
4/8
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 80 times.
✗ Branch 7 not taken.
80 if (screen_x < 0 || screen_x > 16 || screen_y < 0 || screen_y > 8) return true;
419 80 return !is_in_current_region(map_scr_xy_to_index(screen_x, screen_y));
420 26839 }
421
422 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
423 // Coordinates are clamped to the world bounds.
424 211378925 int get_screen_for_world_xy(int x, int y)
425 {
426
2/2
✓ Branch 0 taken 188591833 times.
✓ Branch 1 taken 22787092 times.
211378925 if (!is_in_scrolling_region())
427 188591833 return cur_screen;
428
429 22787092 int dx = std::clamp(x, 0, world_w - 1) / 256;
430 22787092 int dy = std::clamp(y, 0, world_h - 1) / 176;
431 22787092 int origin_screen_x = cur_screen % 16;
432 22787092 int origin_screen_y = cur_screen / 16;
433 22787092 int scr_x = origin_screen_x + dx;
434 22787092 int scr_y = origin_screen_y + dy;
435 22787092 return map_scr_xy_to_index(scr_x, scr_y);
436 211378925 }
437
438 32518504 int get_screen_for_rpos(rpos_t rpos)
439 {
440 32518504 int origin_screen_x = cur_screen % 16;
441 32518504 int origin_screen_y = cur_screen / 16;
442 32518504 int screen = static_cast<int32_t>(rpos) / 176;
443 32518504 int scr_x = origin_screen_x + screen%cur_region.screen_width;
444 32518504 int scr_y = origin_screen_y + screen/cur_region.screen_width;
445 32518504 return map_scr_xy_to_index(scr_x, scr_y);
446 }
447
448 773069469 rpos_handle_t get_rpos_handle(rpos_t rpos, int layer)
449 {
450 DCHECK_LAYER_ZERO_INDEX(layer);
451
2/2
✓ Branch 0 taken 740688925 times.
✓ Branch 1 taken 32380544 times.
773069469 if (!is_in_scrolling_region())
452 740688925 return {get_scr_layer(cur_screen, layer), cur_screen, layer, rpos, RPOS_TO_POS(rpos)};
453 32380544 int screen = get_screen_for_rpos(rpos);
454 32380544 mapscr* scr = get_scr_layer(screen, layer);
455 32380544 return {scr, screen, layer, rpos, RPOS_TO_POS(rpos)};
456 773069469 }
457
458 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
459 // Coordinates are clamped to the world bounds.
460 3485510948 rpos_handle_t get_rpos_handle_for_world_xy(int x, int y, int layer)
461 {
462 3485510948 x = std::clamp(x, 0, world_w - 1);
463 3485510948 y = std::clamp(y, 0, world_h - 1);
464
465 DCHECK_LAYER_ZERO_INDEX(layer);
466
2/2
✓ Branch 0 taken 3457773776 times.
✓ Branch 1 taken 27737172 times.
3485510948 if (!is_in_scrolling_region())
467 {
468 3457773776 int pos = COMBOPOS(x, y);
469 3457773776 return {get_scr_layer(cur_screen, layer), cur_screen, layer, (rpos_t)pos, pos};
470 }
471 27737172 return get_rpos_handle(COMBOPOS_REGION(x, y), layer);
472 3485510948 }
473
474 // Return a rpos_handle_t for a screen-specific `pos` (0-175).
475 44 rpos_handle_t get_rpos_handle_for_screen(int screen, int layer, int pos)
476 {
477 DCHECK_LAYER_ZERO_INDEX(layer);
478 44 return {get_scr_layer(screen, layer), screen, layer, POS_TO_RPOS(pos, screen), pos};
479 }
480
481 // Return a rpos_handle_t for a screen-specific `pos` (0-175).
482 // Use this instead of the other `get_pos_handle_for_screen` if you already have a reference to the screen.
483 62169 rpos_handle_t get_rpos_handle_for_scr(mapscr* scr, int layer, int pos)
484 {
485 DCHECK_LAYER_ZERO_INDEX(layer);
486 62169 return {scr, scr->screen, layer, POS_TO_RPOS(pos, scr->screen), pos};
487 }
488
489 25081733 void change_rpos_handle_layer(rpos_handle_t& rpos_handle, int layer)
490 {
491 DCHECK_LAYER_ZERO_INDEX(layer);
492 25081733 rpos_handle.layer = layer;
493 25081733 rpos_handle.scr = get_scr_layer(rpos_handle.screen, layer);
494 25081733 }
495
496 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
497 // Coordinates are clamped to the world bounds.
498 52808 combined_handle_t get_combined_handle_for_world_xy(int x, int y, int layer)
499 {
500 DCHECK_LAYER_ZERO_INDEX(layer);
501
502 52808 x = std::clamp(x, 0, world_w - 1);
503 52808 y = std::clamp(y, 0, world_h - 1);
504
505 52808 auto maybe_ffc_handle = getFFCAt(x, y);
506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52808 times.
52808 if (maybe_ffc_handle)
507 return maybe_ffc_handle.value();
508
509 52808 auto rpos = COMBOPOS_REGION_B(x, y);
510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52808 times.
52808 if (rpos == rpos_t::None)
511 return rpos_handle_t();
512 52808 return get_rpos_handle(rpos, layer);
513 52808 }
514
515 // These functions all return _temporary_ screens. Any modifications made to them (either by the engine
516 // directly or via zscript) only last until the next area is loaded (via loadscr).
517
518 // Returns the screen containing the (x, y) world position.
519 1625243098 mapscr* get_scr_for_world_xy(int x, int y)
520 {
521 // Quick path, but should work the same without.
522
2/2
✓ Branch 0 taken 1614110938 times.
✓ Branch 1 taken 11132160 times.
1625243098 if (!is_in_scrolling_region()) return origin_scr;
523 11132160 return get_scr(get_screen_for_world_xy(x, y));
524 1625243098 }
525
526 24361310 mapscr* get_scr_for_rpos(rpos_t rpos)
527 {
528 // Quick path, but should work the same without.
529
2/2
✓ Branch 0 taken 24223364 times.
✓ Branch 1 taken 137946 times.
24361310 if (!is_in_scrolling_region()) return origin_scr;
530 137946 return get_scr(get_screen_for_rpos(rpos));
531 24361310 }
532
533 14 mapscr* get_scr_for_rpos_layer(rpos_t rpos, int layer)
534 {
535 14 return get_scr_layer(get_screen_for_rpos(rpos), layer);
536 }
537
538 // Note: layer=0 is the base screen, 1 is the first layer, etc.
539 2295746537 mapscr* get_scr_for_world_xy_layer(int x, int y, int layer)
540 {
541 DCHECK_LAYER_ZERO_INDEX(layer);
542
2/2
✓ Branch 0 taken 2284329059 times.
✓ Branch 1 taken 11417478 times.
2295746537 if (!is_in_scrolling_region()) return get_scr_layer(cur_screen, layer);
543
2/2
✓ Branch 0 taken 708094 times.
✓ Branch 1 taken 10709384 times.
11417478 return layer == 0 ?
544 708094 get_scr_for_world_xy(x, y) :
545 10709384 get_scr_layer(get_screen_for_world_xy(x, y), layer);
546 2295746537 }
547
548 1825611855 int get_region_screen_offset(int screen)
549 {
550 1825611855 return get_region_relative_dx(screen) + get_region_relative_dy(screen) * cur_region.screen_width;
551 }
552
553 654673804 int get_screen_for_region_index_offset(int offset)
554 {
555 654673804 int scr_dx = offset % cur_region.screen_width;
556 654673804 int scr_dy = offset / cur_region.screen_width;
557 654673804 int screen = cur_screen + scr_dx + scr_dy*16;
558 654673804 return screen;
559 }
560
561 654489967 mapscr* get_scr_for_region_index_offset(int offset)
562 {
563 654489967 int screen = get_screen_for_region_index_offset(offset);
564 654489967 return get_scr(screen);
565 }
566
567 // The screen at (map, screen) must exist.
568 1419295265 mapscr* get_scr(int map, int screen)
569 {
570 1419295265 mapscr* scr = get_scr_maybe(map, screen);
571
1/2
✓ Branch 0 taken 1419295265 times.
✗ Branch 1 not taken.
1419295265 CHECK(scr);
572 1419295265 return scr;
573 }
574
575 836826132 mapscr* get_scr(int screen)
576 {
577 836826132 return get_scr(cur_map, screen);
578 }
579
580 // Returns null if active screen does not exist.
581 1448839509 mapscr* get_scr_maybe(int map, int screen)
582 {
583 DCHECK_RANGE_INCLUSIVE(screen, 0, 135);
584
585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1448839509 times.
1448839509 if (map == cur_map)
586 {
587
2/2
✓ Branch 0 taken 1428065417 times.
✓ Branch 1 taken 20774092 times.
1448839509 if (screen == cur_screen)
588 1428065417 return origin_scr;
589
590 20774092 int index = screen*7;
591
2/2
✓ Branch 0 taken 20763002 times.
✓ Branch 1 taken 11090 times.
20774092 if (temporary_screens[index])
592 20763002 return temporary_screens[index];
593
594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11090 times.
11090 if (screen == home_screen)
595 return special_warp_return_scr;
596 11090 }
597
598
3/6
✓ Branch 0 taken 11090 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11090 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11090 times.
11090 if (screenscrolling && map == scrolling_map && !FFCore.ScrollingScreensAll.empty())
599 {
600 11090 int index = screen*7;
601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11090 times.
11090 if (FFCore.ScrollingScreensAll[index])
602 11090 return FFCore.ScrollingScreensAll[index];
603 }
604
605 return nullptr;
606 1448839509 }
607
608 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
609 7030850372 mapscr* get_scr_layer(int map, int screen, int layer)
610 {
611 DCHECK_LAYER_ZERO_INDEX(layer);
612
2/2
✓ Branch 0 taken 6450870118 times.
✓ Branch 1 taken 579980254 times.
7030850372 if (layer == 0)
613 579980254 return get_scr(map, screen);
614
615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6450870118 times.
6450870118 if (map == cur_map)
616 {
617 6450870118 int index = screen*7 + layer;
618
2/2
✓ Branch 0 taken 6450801730 times.
✓ Branch 1 taken 68388 times.
6450870118 if (temporary_screens[index])
619 6450801730 return temporary_screens[index];
620
621
2/2
✓ Branch 0 taken 1848 times.
✓ Branch 1 taken 66540 times.
68388 if (screen == home_screen)
622 1848 return &special_warp_return_scrs[layer];
623 66540 }
624
625
1/2
✓ Branch 0 taken 66540 times.
✗ Branch 1 not taken.
66540 if (screenscrolling && map == scrolling_map && !FFCore.ScrollingScreensAll.empty())
626 {
627 66540 int index = screen*7 + layer;
628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66540 times.
66540 if (FFCore.ScrollingScreensAll[index])
629 66540 return FFCore.ScrollingScreensAll[index];
630 }
631
632 NOTREACHED();
633 7030850372 }
634
635 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
636 6633290018 mapscr* get_scr_layer(int screen, int layer)
637 {
638 6633290018 return get_scr_layer(cur_map, screen, layer);
639 }
640
641 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
642 // Return nullptr if screen is not valid.
643 395487061 mapscr* get_scr_layer_valid(int screen, int layer)
644 {
645
2/2
✓ Branch 0 taken 77942884 times.
✓ Branch 1 taken 317544177 times.
395487061 if (mapscr* scr = get_scr_layer(cur_map, screen, layer); scr->is_valid())
646 77942884 return scr;
647 317544177 return nullptr;
648 395487061 }
649
650 397 mapscr* get_scr_current_region_dir(int screen, direction dir)
651 {
652 397 int x = get_region_relative_dx(screen);
653 397 int y = get_region_relative_dy(screen);
654
3/4
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 327 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 70 times.
397 if (dir == left && x == 0)
655 70 return nullptr;
656
3/4
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 235 times.
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
327 if (dir == right && x == 15)
657 return nullptr;
658
3/4
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 279 times.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
327 if (dir == down && y == 7)
659 return nullptr;
660
3/4
✓ Branch 0 taken 187 times.
✓ Branch 1 taken 140 times.
✓ Branch 2 taken 187 times.
✗ Branch 3 not taken.
327 if (dir == up && y == 0)
661 187 return nullptr;
662
663 140 screen = screen_index_direction(screen, dir);
664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 140 times.
140 if (is_in_current_region(screen))
665 return get_scr(screen);
666
667 140 return nullptr;
668 397 }
669
670 183837 ffc_handle_t get_ffc_handle(ffc_id_t id)
671 {
672 183837 uint8_t screen = get_screen_for_region_index_offset(id / MAXFFCS);
673 183837 uint8_t i = id % MAXFFCS;
674 183837 mapscr* scr = get_scr(screen);
675 183837 ffcdata* ffc = &scr->getFFC(id % MAXFFCS);
676 183837 return {scr, screen, id, i, ffc};
677 }
678
679 34497 std::pair<int32_t, int32_t> translate_screen_coordinates_to_world(int screen, int x, int y)
680 {
681 34497 x += get_region_relative_dx(screen) * 256;
682 34497 y += get_region_relative_dy(screen) * 176;
683 34497 return {x, y};
684 }
685
686 1023791 std::pair<int32_t, int32_t> translate_screen_coordinates_to_world(int screen)
687 {
688 1023791 int x = get_region_relative_dx(screen) * 256;
689 1023791 int y = get_region_relative_dy(screen) * 176;
690 1023791 return {x, y};
691 }
692
693 12086332830 int32_t COMBOPOS(int32_t x, int32_t y)
694 {
695 DCHECK(x >= 0 && x < 256 && y >= 0 && y < 176);
696 12086332830 return (y & 0xF0) + (x >> 4);
697 }
698 int32_t COMBOPOS_B(int32_t x, int32_t y)
699 {
700 if(unsigned(x) >= 256 || unsigned(y) >= 176)
701 return -1;
702 return (y & 0xF0) + (x >> 4);
703 }
704 3320314773 int32_t COMBOX(int32_t pos)
705 {
706 3320314773 return pos % 16 * 16;
707 }
708 3320314773 int32_t COMBOY(int32_t pos)
709 {
710 3320314773 return pos & 0xF0;
711 }
712
713 112408941 rpos_t COMBOPOS_REGION(int32_t x, int32_t y)
714 {
715
2/2
✓ Branch 0 taken 83856295 times.
✓ Branch 1 taken 28552646 times.
112408941 if (!is_in_scrolling_region())
716 83856295 return (rpos_t) COMBOPOS(x, y);
717
718 DCHECK(is_in_world_bounds(x, y));
719 28552646 int scr_dx = x / (16*16);
720 28552646 int scr_dy = y / (11*16);
721 28552646 int pos = COMBOPOS(x%256, y%176);
722 28552646 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + pos);
723 112408941 }
724 6280225517 rpos_t COMBOPOS_REGION_B(int32_t x, int32_t y)
725 {
726
2/2
✓ Branch 0 taken 1390337 times.
✓ Branch 1 taken 6278835180 times.
6280225517 if (!is_in_world_bounds(x, y))
727 1390337 return rpos_t::None;
728
729 6278835180 int scr_dx = x / (16*16);
730 6278835180 int scr_dy = y / (11*16);
731 6278835180 int pos = COMBOPOS(x%256, y%176);
732 6278835180 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + pos);
733 6280225517 }
734 25262050 std::pair<int32_t, int32_t> COMBOXY_REGION(rpos_t rpos)
735 {
736 25262050 int scr_index = static_cast<int32_t>(rpos) / 176;
737 25262050 int scr_dx = scr_index % cur_region.screen_width;
738 25262050 int scr_dy = scr_index / cur_region.screen_width;
739 25262050 int pos = RPOS_TO_POS(rpos);
740 25262050 int x = scr_dx*16*16 + COMBOX(pos);
741 25262050 int y = scr_dy*11*16 + COMBOY(pos);
742 25262050 return {x, y};
743 }
744 60396 int32_t COMBOX_REGION(rpos_t rpos)
745 {
746 60396 auto [x, y] = COMBOXY_REGION(rpos);
747 60396 return x;
748 }
749 12225 int32_t COMBOY_REGION(rpos_t rpos)
750 {
751 12225 auto [x, y] = COMBOXY_REGION(rpos);
752 12225 return y;
753 }
754
755 70177 rpos_t COMBOPOS_REGION_INDEX(int32_t x, int32_t y)
756 {
757 DCHECK(is_in_world_bounds(x, y));
758
1/2
✓ Branch 0 taken 70177 times.
✗ Branch 1 not taken.
70177 if (!is_in_scrolling_region())
759 70177 return (rpos_t)(x + y * 16);
760
761 int scr_dx = x / 16;
762 int scr_dy = y / 11;
763 x %= 16;
764 y %= 11;
765 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + x + y * 16);
766 70177 }
767 70632 std::pair<int32_t, int32_t> COMBOXY_REGION_INDEX(rpos_t rpos)
768 {
769 70632 int scr_index = static_cast<int32_t>(rpos) / 176;
770 70632 int scr_dx = scr_index % cur_region.screen_width;
771 70632 int scr_dy = scr_index / cur_region.screen_width;
772 70632 int pos = RPOS_TO_POS(rpos);
773 70632 int x = scr_dx*16 + pos%16;
774 70632 int y = scr_dy*11 + pos/16;
775 70632 return {x, y};
776 }
777
778 82239058 int32_t mapind(int32_t map, int32_t scr)
779 {
780 82239058 return map * MAPSCRSNORMAL + scr;
781 }
782
783 FONT *get_zc_font(int index);
784
785 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
786 extern movingblock mblock2; //mblock[4]?
787 extern portal mirror_portal;
788
789 void Z_message_d(const char *format,...)
790 {
791 #ifdef _DEBUG
792 char buf[512];
793 va_list ap;
794 va_start(ap, format);
795 vsprintf(buf, format, ap);
796 va_end(ap);
797
798 al_trace("%s",buf);
799 #else
800 format=format;
801 #endif
802 }
803
804
805
806 bool checktrigger=false;
807
808 void debugging_box(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
809 {
810 //reference/optimization: the start of the unused drawing command index can now be queried. -Gleeok
811 int32_t index = script_drawing_commands.GetNext();
812
813 if(index < 0)
814 return;
815
816 int32_t *sdci = &script_drawing_commands[index][0];
817
818 sdci[0] = RECTR;
819 sdci[1] = 30000;
820 sdci[2] = x1*10000;
821 sdci[3] = y1*10000;
822 sdci[4] = x2*10000;
823 sdci[5] = y2*10000;
824 sdci[6] = 10000;
825 sdci[7] = 10000;
826 sdci[8] = 0;
827 sdci[9] = 0;
828 sdci[10] = 0;
829 sdci[11] = 10000;
830 sdci[12] = 1280000;
831 }
832
833 void clear_dmap(word i)
834 {
835 DMaps[i].clear();
836 }
837
838 void clear_dmaps()
839 {
840 for(int32_t i=0; i<MAXDMAPS; i++)
841 {
842 clear_dmap(i);
843 }
844 }
845
846 222644040 int32_t isdungeon(int32_t dmap, int32_t screen)
847 {
848
2/2
✓ Branch 0 taken 222598360 times.
✓ Branch 1 taken 45680 times.
222644040 if (dmap < 0) dmap = cur_dmap;
849
850 // dungeons can have any dlevel above 0
851
2/2
✓ Branch 0 taken 122174782 times.
✓ Branch 1 taken 100469258 times.
222644040 if((DMaps[dmap].type&dmfTYPE) == dmDNGN)
852 {
853
2/2
✓ Branch 0 taken 9961 times.
✓ Branch 1 taken 100459297 times.
100469258 if (get_canonical_scr(cur_map, screen)->flags6&fCAVEROOM)
854 9961 return 0;
855
856 100459297 return 1;
857 }
858
859 // dlevels that aren't dungeons are caves
860
2/2
✓ Branch 0 taken 36827 times.
✓ Branch 1 taken 122137955 times.
122174782 if (get_canonical_scr(cur_map, screen)->flags6&fDUNGEONROOM)
861 36827 return 1;
862
863 122137955 return 0;
864 222644040 }
865
866 39715626 int32_t isdungeon(int32_t screen)
867 {
868 39715626 return isdungeon(cur_dmap, screen);
869 }
870
871 182801690 int32_t isdungeon()
872 {
873 182801690 return isdungeon(cur_dmap, hero_screen);
874 }
875
876 88821 bool canPermSecret(int32_t dmap, int32_t screen)
877 {
878
2/2
✓ Branch 0 taken 13843 times.
✓ Branch 1 taken 74978 times.
88821 return (!isdungeon(dmap, screen) || get_qr(qr_DUNGEON_DMAPS_PERM_SECRETS));
879 }
880
881 1368839560 int32_t MAPCOMBO(int32_t x, int32_t y)
882 {
883 1368839560 x = vbound(x, 0, world_w-1);
884 1368839560 y = vbound(y, 0, world_h-1);
885 1368839560 int pos = COMBOPOS(x%256, y%176);
886 1368839560 mapscr* scr = get_scr_for_world_xy(x, y);
887 1368839560 return scr->data[pos];
888 }
889
890 //specific layers 1 to 6
891 1700215249 int32_t MAPCOMBOL(int32_t layer,int32_t x,int32_t y)
892 {
893 DCHECK(layer >= 1 && layer <= 6);
894
3/4
✓ Branch 0 taken 1679926399 times.
✓ Branch 1 taken 20288850 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1679926399 times.
1700215249 if (!is_in_world_bounds(x, y) || layer <= 0)
895 20288850 return 0;
896
897 1679926399 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
898
2/2
✓ Branch 0 taken 494035176 times.
✓ Branch 1 taken 1185891223 times.
1679926399 if (!m->is_valid())
899 1185891223 return 0;
900
901 494035176 int pos = COMBOPOS(x%256, y%176);
902 494035176 return m->data[pos];
903 1700215249 }
904
905 int32_t MAPCSETL(int32_t layer,int32_t x,int32_t y)
906 {
907 DCHECK(layer >= 1 && layer <= 6);
908 if (!is_in_world_bounds(x, y) || layer <= 0)
909 return 0;
910
911 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
912 if (!m->is_valid())
913 return 0;
914
915 int pos = COMBOPOS(x%256, y%176);
916 return m->cset[pos];
917 }
918
919 189244 int32_t MAPFLAGL(int32_t layer,int32_t x,int32_t y)
920 {
921 DCHECK(layer >= 1 && layer <= 6);
922
2/4
✓ Branch 0 taken 189244 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 189244 times.
189244 if (!is_in_world_bounds(x, y) || layer <= 0)
923 return 0;
924
925 189244 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
926
2/2
✓ Branch 0 taken 148850 times.
✓ Branch 1 taken 40394 times.
189244 if (!m->is_valid())
927 40394 return 0;
928
929 148850 int pos = COMBOPOS(x%256, y%176);
930 148850 return m->sflag[pos];
931 189244 }
932
933 6281 int32_t COMBOTYPEL(int32_t layer,int32_t x,int32_t y)
934 {
935 DCHECK(layer >= 1 && layer <= 6);
936
2/4
✓ Branch 0 taken 6281 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6281 times.
6281 if (!is_in_world_bounds(x, y) || layer <= 0)
937 return 0;
938
939 6281 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
940
2/2
✓ Branch 0 taken 5809 times.
✓ Branch 1 taken 472 times.
6281 if (!m->is_valid())
941 472 return 0;
942
943 5809 int pos = COMBOPOS(x%256, y%176);
944 5809 return combobuf[m->data[pos]].type;
945 6281 }
946
947 189244 int32_t MAPCOMBOFLAGL(int32_t layer,int32_t x,int32_t y)
948 {
949 DCHECK(layer >= 1 && layer <= 6);
950
2/4
✓ Branch 0 taken 189244 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 189244 times.
189244 if (!is_in_world_bounds(x, y) || layer <= 0)
951 return 0;
952
953 189244 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
954
2/2
✓ Branch 0 taken 148850 times.
✓ Branch 1 taken 40394 times.
189244 if (!m->is_valid())
955 40394 return 0;
956
957 148850 int pos = COMBOPOS(x%256, y%176);
958 148850 return combobuf[m->data[pos]].flag;
959 189244 }
960
961
962 // True if the FFC covers x, y and is not ethereal or a changer.
963 2465192826 bool ffcIsAt(const ffc_handle_t& ffc_handle, int32_t x, int32_t y)
964 {
965
2/2
✓ Branch 0 taken 744708986 times.
✓ Branch 1 taken 1720483840 times.
2465192826 if (ffc_handle.data()<=0)
966 744708986 return false;
967
968
2/2
✓ Branch 0 taken 300883564 times.
✓ Branch 1 taken 1419600276 times.
1720483840 if((ffc_handle.ffc->flags&(ffc_changer|ffc_ethereal))!=0)
969 300883564 return false;
970
971 1419600276 int32_t fx=ffc_handle.ffc->x.getInt();
972
4/4
✓ Branch 0 taken 976080557 times.
✓ Branch 1 taken 443519719 times.
✓ Branch 2 taken 865979117 times.
✓ Branch 3 taken 110101440 times.
1419600276 if(x<fx || x>fx+(ffc_handle.scr->ffEffectWidth(ffc_handle.i)-1)) // FFC sizes are weird.
973 1309498836 return false;
974
975 110101440 int32_t fy=ffc_handle.ffc->y.getInt();
976
4/4
✓ Branch 0 taken 80120795 times.
✓ Branch 1 taken 29980645 times.
✓ Branch 2 taken 60054856 times.
✓ Branch 3 taken 20065939 times.
110101440 if(y<fy || y>fy+(ffc_handle.scr->ffEffectHeight(ffc_handle.i)-1))
977 90035501 return false;
978
979 20065939 return true;
980 2465192826 }
981
982 993538382 int32_t MAPFFCOMBO(int32_t x,int32_t y)
983 {
984
2/2
✓ Branch 0 taken 13161801 times.
✓ Branch 1 taken 980376581 times.
993538382 if (auto ffc_handle = getFFCAt(x, y))
985 13161801 return ffc_handle->data();
986 980376581 return 0;
987 993538382 }
988
989 206208 int32_t MAPCSET(int32_t x, int32_t y)
990 {
991
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206208 times.
206208 if (!is_in_world_bounds(x, y))
992 return 0;
993 206208 mapscr* scr = get_scr_for_world_xy(x, y);
994 206208 int pos = COMBOPOS(x%256, y%176);
995 206208 return scr->cset[pos];
996 206208 }
997
998 73123812 int32_t MAPFLAG(int32_t x, int32_t y)
999 {
1000
2/2
✓ Branch 0 taken 27912 times.
✓ Branch 1 taken 73095900 times.
73123812 if (!is_in_world_bounds(x, y))
1001 27912 return 0;
1002 73095900 mapscr* scr = get_scr_for_world_xy(x, y);
1003 73095900 int pos = COMBOPOS(x%256, y%176);
1004 73095900 return scr->sflag[pos];
1005 73123812 }
1006
1007 164755311 int32_t COMBOTYPE(int32_t x,int32_t y)
1008 {
1009 164755311 int32_t b=1;
1010
2/2
✓ Branch 0 taken 96171140 times.
✓ Branch 1 taken 68584171 times.
164755311 if(x&8) b<<=2;
1011
2/2
✓ Branch 0 taken 82898991 times.
✓ Branch 1 taken 81856320 times.
164755311 if(y&8) b<<=1;
1012
1013
2/2
✓ Branch 0 taken 329503584 times.
✓ Branch 1 taken 164746233 times.
494249817 for (int32_t i = 0; i <= 1; ++i)
1014 {
1015
2/2
✓ Branch 0 taken 318345136 times.
✓ Branch 1 taken 11158448 times.
329503584 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1016 {
1017
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 318345136 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
318345136 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x, y, i)) return cNONE;
1018 318345136 }
1019 else
1020 {
1021
4/4
✓ Branch 0 taken 12230 times.
✓ Branch 1 taken 11146218 times.
✓ Branch 2 taken 3152 times.
✓ Branch 3 taken 9078 times.
11158448 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x, y, i)) return cNONE;
1022 }
1023 329494506 }
1024
1025 164746233 newcombo const& cmb = combobuf[MAPCOMBO(x,y)];
1026
5/6
✓ Branch 0 taken 3588506 times.
✓ Branch 1 taken 161157727 times.
✓ Branch 2 taken 3005570 times.
✓ Branch 3 taken 582936 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3005570 times.
164746233 if (cmb.type == cWATER && (cmb.walk&b) && ((cmb.walk>>4)&b))
1027 {
1028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3005570 times.
3005570 if(cmb.usrflags&cflag4) return cSHALLOWWATER;
1029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3005570 times.
3005570 if(cmb.usrflags&cflag3) return cNONE;
1030 3005570 }
1031 164746233 return cmb.type;
1032 164755311 }
1033
1034 49774740 int32_t FFCOMBOTYPE(int32_t x,int32_t y)
1035 {
1036 49774740 return combobuf[MAPFFCOMBO(x,y)].type;
1037 }
1038
1039 4971160 int32_t FFORCOMBO(int32_t x, int32_t y)
1040 {
1041
2/2
✓ Branch 0 taken 58516 times.
✓ Branch 1 taken 4912644 times.
4971160 if (auto ffc_handle = getFFCAt(x, y))
1042 58516 return ffc_handle->data();
1043
1044 4912644 return MAPCOMBO(x,y);
1045 4971160 }
1046
1047 int32_t FFORCOMBOTYPE(int32_t x, int32_t y)
1048 {
1049 for (int32_t i = 0; i <= 1; ++i)
1050 {
1051 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1052 {
1053 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,i)) return cNONE;
1054 }
1055 else
1056 {
1057 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x,y,i)) return cNONE;
1058 }
1059 }
1060 int32_t b=1;
1061
1062 if(x&8) b<<=2;
1063
1064 if(y&8) b<<=1;
1065 newcombo const& cmb = combobuf[FFORCOMBO(x,y)];
1066 if (cmb.type == cWATER && (cmb.usrflags&cflag4) && (cmb.walk&b)) return cSHALLOWWATER;
1067 if (cmb.type == cWATER && (cmb.usrflags&cflag3) && (cmb.walk&b)) return cNONE;
1068 return cmb.type;
1069 }
1070
1071 int32_t FFORCOMBO_L(int32_t layer, int32_t x, int32_t y)
1072 {
1073 if (auto ffc_handle = getFFCAt(x, y))
1074 return ffc_handle->data();
1075
1076 return layer ? MAPCOMBOL(layer, x, y) : MAPCOMBO(x,y);
1077 }
1078
1079 int32_t FFORCOMBOTYPE_L(int32_t layer, int32_t x, int32_t y)
1080 {
1081 return combobuf[FFORCOMBO_L(layer,x,y)].type;
1082 }
1083
1084 69621828 int32_t MAPCOMBOFLAG(int32_t x,int32_t y)
1085 {
1086
2/2
✓ Branch 0 taken 27624 times.
✓ Branch 1 taken 69594204 times.
69621828 if (!is_in_world_bounds(x, y))
1087 27624 return 0;
1088
1089 69594204 mapscr* scr = get_scr_for_world_xy(x, y);
1090 69594204 int pos = COMBOPOS(x%256, y%176);
1091 69594204 return combobuf[scr->data[pos]].flag;
1092 69621828 }
1093
1094 56339950 int32_t MAPFFCOMBOFLAG(int32_t x,int32_t y)
1095 {
1096
2/2
✓ Branch 0 taken 746177 times.
✓ Branch 1 taken 55593773 times.
56339950 if (auto ffc_handle = getFFCAt(x, y))
1097 746177 return ffc_handle->cflag();
1098
1099 55593773 return 0;
1100 56339950 }
1101
1102 1306189118 std::optional<ffc_handle_t> getFFCAt(int32_t x, int32_t y)
1103 {
1104 2781670220 return find_ffc([&](const ffc_handle_t& ffc_handle) {
1105 1475481102 return ffcIsAt(ffc_handle, x, y);
1106 });
1107 }
1108
1109 3044 int32_t MAPCOMBO(const rpos_handle_t& rpos_handle)
1110 {
1111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3044 times.
3044 if (!rpos_handle.scr->is_valid()) return 0;
1112 3044 return rpos_handle.data();
1113 3044 }
1114
1115 3154054337 int32_t MAPCOMBO2(int32_t layer, int32_t x, int32_t y)
1116 {
1117 DCHECK_LAYER_NEG1_INDEX(layer);
1118
2/2
✓ Branch 0 taken 22351294 times.
✓ Branch 1 taken 3131703043 times.
3154054337 if (!is_in_world_bounds(x, y)) return 0;
1119
2/2
✓ Branch 0 taken 3062611487 times.
✓ Branch 1 taken 69091556 times.
3131703043 if (layer == -1) return MAPCOMBO(x, y);
1120
1121 3062611487 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1122
2/2
✓ Branch 0 taken 2108088265 times.
✓ Branch 1 taken 954523222 times.
3062611487 if (!rpos_handle.scr->is_valid()) return 0;
1123
1124 954523222 return rpos_handle.data();
1125 3154054337 }
1126
1127 17334032 static void _handle_screen_load_trigger(const combined_handle_t& handle)
1128 {
1129 17334032 auto cid = handle.data();
1130 17334032 auto* cmb = &handle.combo();
1131 17334032 bool done = false;
1132 17334032 std::set<int32_t> visited;
1133
2/2
✓ Branch 0 taken 17334032 times.
✓ Branch 1 taken 17334053 times.
34668085 while(!done)
1134 {
1135
2/4
✓ Branch 0 taken 17334053 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17334053 times.
17334053 if(visited.contains(cid))
1136 {
1137 Z_error("Combo '%d' was part of an infinite trigger loop, breaking out of loop", cid);
1138 break; // prevent infinite loop
1139 }
1140
1/2
✓ Branch 0 taken 17334053 times.
✗ Branch 1 not taken.
17334053 visited.insert(cid);
1141
1142 17334053 done = true; // don't loop again unless something changes
1143
2/2
✓ Branch 0 taken 17334032 times.
✓ Branch 1 taken 592658 times.
17926690 for(size_t idx = 0; idx < cmb->triggers.size(); ++idx)
1144 {
1145 592658 auto& trig = cmb->triggers[idx];
1146
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 592586 times.
592658 if (trig.triggerflags[4] & combotriggerSCREENLOAD)
1147
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 do_trigger_combo(handle, idx);
1148 592586 else continue; // can skip checking handle.data()
1149
1150
3/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 51 times.
72 if(handle.data() != cid)
1151 {
1152
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 cid = handle.data();
1153
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 cmb = &handle.combo();
1154 21 done = false; // loop again for the new combo
1155 21 break;
1156 }
1157 51 }
1158 }
1159 17334032 }
1160 51669 static void handle_screen_load_trigger(const screen_handles_t& screen_handles)
1161 {
1162 51669 for_every_combo_in_screen(screen_handles, _handle_screen_load_trigger);
1163 51669 }
1164 34721 void handle_region_load_trigger()
1165 {
1166
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 34569 times.
34721 if (is_in_scrolling_region())
1167 {
1168
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 19456 times.
19608 for (int screen = 0; screen < 128; screen++)
1169 {
1170
2/2
✓ Branch 0 taken 18156 times.
✓ Branch 1 taken 1300 times.
19456 if (is_in_current_region(screen))
1171 1300 handle_screen_load_trigger(create_screen_handles_one(get_scr(screen)));
1172 19456 }
1173 152 }
1174 34569 else handle_screen_load_trigger(create_screen_handles_one(get_scr(hero_screen)));
1175 34721 }
1176
1177 15800 static void apply_state_changes_to_screen(mapscr& scr, int32_t map, int32_t screen, int32_t flags, bool secrets_do_replay_comment)
1178 {
1179 15800 auto screen_handles = create_screen_handles_one(&scr);
1180
1181
3/4
✓ Branch 0 taken 539 times.
✓ Branch 1 taken 15261 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 539 times.
15800 if ((flags & mSECRET) && canPermSecret(cur_dmap, screen))
1182 {
1183 539 reveal_hidden_stairs(&scr, screen, false);
1184 539 bool do_layers = false;
1185 539 bool from_active_screen = false;
1186 539 trigger_secrets_for_screen_internal(screen_handles, do_layers, from_active_screen, -3, secrets_do_replay_comment);
1187 539 }
1188
1/2
✓ Branch 0 taken 15800 times.
✗ Branch 1 not taken.
15800 if (flags & mLIGHTBEAM)
1189 {
1190 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
1191 if (rpos_handle.ctype() == cLIGHTTARGET)
1192 {
1193 if (!(rpos_handle.combo().usrflags&cflag1)) //Unlit version
1194 rpos_handle.increment_data();
1195 }
1196 });
1197 }
1198
1199 15800 int lvl = DMaps[cur_dmap].level;
1200 15800 toggle_switches(game->lvlswitches[lvl], true, screen_handles);
1201 15800 toggle_gswitches_load(screen_handles);
1202
1203
2/2
✓ Branch 0 taken 15708 times.
✓ Branch 1 taken 92 times.
15800 if(flags&mLOCKBLOCK) // if special stuff done before
1204 {
1205 92 remove_screenstatecombos2(screen_handles, false, cLOCKBLOCK, cLOCKBLOCK2);
1206 92 }
1207
1208
1/2
✓ Branch 0 taken 15800 times.
✗ Branch 1 not taken.
15800 if(flags&mBOSSLOCKBLOCK) // if special stuff done before
1209 {
1210 remove_screenstatecombos2(screen_handles, false, cBOSSLOCKBLOCK, cBOSSLOCKBLOCK2);
1211 }
1212
1213
1/2
✓ Branch 0 taken 15800 times.
✗ Branch 1 not taken.
15800 if(flags&mCHEST) // if special stuff done before
1214 {
1215 remove_screenstatecombos2(screen_handles, false, cCHEST, cCHEST2);
1216 }
1217
1218
1/2
✓ Branch 0 taken 15800 times.
✗ Branch 1 not taken.
15800 if(flags&mCHEST) // if special stuff done before
1219 {
1220 remove_screenstatecombos2(screen_handles, false, cLOCKEDCHEST, cLOCKEDCHEST2);
1221 }
1222
1223
1/2
✓ Branch 0 taken 15800 times.
✗ Branch 1 not taken.
15800 if(flags&mBOSSCHEST) // if special stuff done before
1224 {
1225 remove_screenstatecombos2(screen_handles, false, cBOSSCHEST, cBOSSCHEST2);
1226 }
1227
1228
1229 15800 int mi = mapind(map, screen);
1230 15800 clear_xdoors_mi(screen_handles, mi);
1231 15800 clear_xstatecombos_mi(screen_handles, mi);
1232
1233 15800 handle_screen_load_trigger(screen_handles);
1234 15800 }
1235
1236 53194 std::optional<mapscr> load_temp_mapscr_and_apply_secrets(int32_t map, int32_t screen, int32_t layer, bool secrets, bool secrets_do_replay_comment)
1237 {
1238
2/4
✓ Branch 0 taken 53194 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53194 times.
53194 if (map < 0 || screen < 0)
1239 return std::nullopt;
1240
1241 53194 const mapscr* source = get_canonical_scr(map, screen);
1242
2/2
✓ Branch 0 taken 40960 times.
✓ Branch 1 taken 12234 times.
53194 if (!source->is_valid())
1243 12234 return std::nullopt;
1244
1245
2/2
✓ Branch 0 taken 8308 times.
✓ Branch 1 taken 32652 times.
40960 if (layer >= 0)
1246 {
1247
2/2
✓ Branch 0 taken 25160 times.
✓ Branch 1 taken 7492 times.
32652 if (source->layermap[layer] <= 0)
1248 25160 return std::nullopt;
1249
1250 7492 source = get_canonical_scr(source->layermap[layer] - 1, source->layerscreen[layer]);
1251
1/2
✓ Branch 0 taken 7492 times.
✗ Branch 1 not taken.
7492 if (!source->is_valid())
1252 return std::nullopt;
1253 7492 }
1254
1255
1/2
✓ Branch 0 taken 15800 times.
✗ Branch 1 not taken.
15800 int flags = secrets ? game->maps[mapind(map, screen)] : 0;
1256 15800 mapscr scr = *source;
1257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15800 times.
15800 apply_state_changes_to_screen(scr, map, screen, flags, secrets_do_replay_comment);
1258
1259 15800 return scr;
1260 53194 }
1261
1262 27203 static int32_t MAPCOMBO3_impl(int32_t map, int32_t screen, int32_t layer, int32_t pos, bool secrets)
1263 {
1264
2/4
✓ Branch 0 taken 27203 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 27203 times.
27203 if (map < 0 || screen < 0) return 0;
1265
1266
2/4
✓ Branch 0 taken 27203 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 27203 times.
27203 if(pos>175 || pos < 0)
1267 return 0;
1268
1269 // TODO: consider caching this (invalidate on any modification via scripting, or anything
1270 // `apply_state_changes_to_screen` checks).
1271
4/5
✓ Branch 0 taken 4976 times.
✓ Branch 1 taken 22227 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4976 times.
✓ Branch 4 taken 22227 times.
32179 if (auto s = load_temp_mapscr_and_apply_secrets(map, screen, layer, secrets))
1272 4976 return s->data[pos];
1273
1274 22227 return 0;
1275 27203 }
1276
1277 // Read from the current temporary screens or, if (map, screen) is not loaded,
1278 // load that screen and apply the relevant secrets before evaluating the combo at that position.
1279 138223152 int32_t MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets)
1280 {
1281 DCHECK_LAYER_NEG1_INDEX(layer);
1282 DCHECK(map >= 0 && screen >= 0);
1283
1284
2/2
✓ Branch 0 taken 138195949 times.
✓ Branch 1 taken 27203 times.
138223152 if (is_in_current_region(map, screen)) return MAPCOMBO2(layer, x, y);
1285
1286 // Screen is not in the current region, so we have to load and trigger some secrets.
1287 27203 int pos = COMBOPOS(x, y);
1288 27203 return MAPCOMBO3_impl(map, screen, layer, pos, secrets);
1289 138223152 }
1290
1291 int32_t MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, rpos_t rpos, bool secrets)
1292 {
1293 DCHECK_LAYER_NEG1_INDEX(layer);
1294 DCHECK(map >= 0 && screen >= 0);
1295 DCHECK(is_valid_rpos(rpos));
1296
1297 if (is_in_current_region(map, screen)) return MAPCOMBO(get_rpos_handle(rpos, layer + 1));
1298
1299 // Screen is not currently loaded, so we have to load and trigger some secrets.
1300 return MAPCOMBO3_impl(map, screen, layer, RPOS_TO_POS(rpos), secrets);
1301 }
1302
1303 int32_t MAPCSET2(int32_t layer,int32_t x,int32_t y)
1304 {
1305 DCHECK_LAYER_NEG1_INDEX(layer);
1306 if (!is_in_world_bounds(x, y))
1307 return 0;
1308 if (layer == -1) return MAPCSET(x, y);
1309
1310 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1311 if (!rpos_handle.scr->is_valid()) return 0;
1312
1313 return rpos_handle.cset();
1314 }
1315
1316 98280110 int32_t MAPFLAG2(int32_t layer,int32_t x,int32_t y)
1317 {
1318 DCHECK_LAYER_NEG1_INDEX(layer);
1319
3/4
✓ Branch 0 taken 1906392 times.
✓ Branch 1 taken 96373718 times.
✓ Branch 2 taken 1906392 times.
✗ Branch 3 not taken.
98280110 if (!get_qr(qr_BUGGED_LAYERED_FLAGS) && (!is_in_world_bounds(x, y)))
1320 return 0;
1321
2/2
✓ Branch 0 taken 80767249 times.
✓ Branch 1 taken 17512861 times.
98280110 if (layer == -1) return MAPFLAG(x, y);
1322
1323 80767249 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1324
2/2
✓ Branch 0 taken 62576546 times.
✓ Branch 1 taken 18190703 times.
80767249 if (!rpos_handle.scr->is_valid()) return 0;
1325
1326 18190703 return rpos_handle.sflag();
1327 98280110 }
1328
1329 2518104 int32_t COMBOTYPE2(int32_t layer,int32_t x,int32_t y)
1330 {
1331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2518104 times.
2518104 if(layer < 1)
1332 {
1333
2/2
✓ Branch 0 taken 5036208 times.
✓ Branch 1 taken 2518104 times.
7554312 for (int32_t i = layer+1; i <= 1; ++i)
1334 {
1335
2/2
✓ Branch 0 taken 4212456 times.
✓ Branch 1 taken 823752 times.
5036208 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1336 {
1337
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4212456 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4212456 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,i)) return cNONE;
1338 4212456 }
1339 else
1340 {
1341
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 823752 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
823752 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x,y,i)) return cNONE;
1342 }
1343 5036208 }
1344 2518104 }
1345
1/2
✓ Branch 0 taken 2518104 times.
✗ Branch 1 not taken.
2518104 if(layer==-1) return COMBOTYPE(x,y);
1346
1347 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1348 if (!rpos_handle.scr->is_valid()) return 0;
1349
1350 return rpos_handle.ctype();
1351 2518104 }
1352
1353 // Returns the flag for the combo at the given position.
1354 // This is also known as an "inherent flag".
1355 96510877 int32_t MAPCOMBOFLAG2(int32_t layer,int32_t x,int32_t y)
1356 {
1357 DCHECK_LAYER_NEG1_INDEX(layer);
1358
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 96510589 times.
96510877 if (!is_in_world_bounds(x, y))
1359 288 return 0;
1360
2/2
✓ Branch 0 taken 80707288 times.
✓ Branch 1 taken 15803301 times.
96510589 if (layer == -1) return MAPCOMBOFLAG(x, y);
1361
1362 80707288 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1363
2/2
✓ Branch 0 taken 62586396 times.
✓ Branch 1 taken 18120892 times.
80707288 if (!rpos_handle.scr->is_valid()) return 0;
1364
1365 18120892 return rpos_handle.cflag();
1366 96510877 }
1367
1368 11742139 bool HASFLAG(int32_t flag, int32_t layer, rpos_t rpos)
1369 {
1370 DCHECK_LAYER_ZERO_INDEX(layer);
1371 11742139 auto rpos_handle = get_rpos_handle(rpos, layer);
1372
2/2
✓ Branch 0 taken 6485404 times.
✓ Branch 1 taken 5256735 times.
11742139 if (!rpos_handle.scr->is_valid()) return false;
1373
2/2
✓ Branch 0 taken 4565 times.
✓ Branch 1 taken 5252170 times.
5256735 if (rpos_handle.sflag() == flag) return true;
1374
2/2
✓ Branch 0 taken 37705 times.
✓ Branch 1 taken 5214465 times.
5252170 if (rpos_handle.cflag() == flag) return true;
1375 5214465 return false;
1376 11742139 }
1377
1378 1713533 bool HASFLAG_ANY(int32_t flag, rpos_t rpos)
1379 {
1380 DCHECK(is_valid_rpos(rpos));
1381
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1713533 times.
1713533 if (rpos > region_max_rpos) return false;
1382
1383
2/2
✓ Branch 0 taken 11742139 times.
✓ Branch 1 taken 1671263 times.
13413402 for(auto q = 0; q < 7; ++q)
1384 {
1385
2/2
✓ Branch 0 taken 42270 times.
✓ Branch 1 taken 11699869 times.
11742139 if(HASFLAG(flag, q, rpos))
1386 42270 return true;
1387 11699869 }
1388 1671263 return false;
1389 1713533 }
1390
1391 const char *screenstate_string[16] =
1392 {
1393 "Door Up", "Door Down", "Door Left", "Door Right", "Item", "Special Item", "No Return",
1394 "Temporary No Return", "Lock Blocks", "Boss Lock Blocks", "Chests", "Locked Chests",
1395 "Boss Locked Chests", "Secrets", "Visited", "Light Beams"
1396 };
1397
1398 34769 void eventlog_mapflags()
1399 {
1400 34769 std::ostringstream oss;
1401
1402 34769 int mi = mapind(cur_map, home_screen);
1403
1/2
✓ Branch 0 taken 34769 times.
✗ Branch 1 not taken.
34769 word g = game->maps[mi] &0x3FFF;
1404
1405
2/4
✓ Branch 0 taken 34769 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34769 times.
✗ Branch 3 not taken.
34769 oss << fmt::format("Screen ({}, {:02X})", cur_map+1, home_screen);
1406
2/2
✓ Branch 0 taken 7038 times.
✓ Branch 1 taken 27731 times.
34769 if(g) // Main States
1407 {
1408 static const int order[] =
1409 {
1410 mSECRET, mITEM, mSPECIALITEM, mLOCKBLOCK, mBOSSLOCKBLOCK,
1411 mCHEST, mLOCKEDCHEST, mBOSSCHEST,
1412 mDOOR_UP, mDOOR_DOWN, mDOOR_LEFT, mDOOR_RIGHT,
1413 mNEVERRET, mTMPNORET
1414 };
1415
1416
1/2
✓ Branch 0 taken 7038 times.
✗ Branch 1 not taken.
7038 oss << " [";
1417 7038 bool comma = false;
1418
2/2
✓ Branch 0 taken 7038 times.
✓ Branch 1 taken 98532 times.
105570 for(int fl : order)
1419 {
1420
2/2
✓ Branch 0 taken 8949 times.
✓ Branch 1 taken 89583 times.
98532 if(!(g&fl))
1421 89583 continue;
1422 8949 byte ind = byte(log2(double(fl)));
1423
2/2
✓ Branch 0 taken 1911 times.
✓ Branch 1 taken 7038 times.
8949 if(comma)
1424
1/2
✓ Branch 0 taken 1911 times.
✗ Branch 1 not taken.
1911 oss << ", ";
1425
1/2
✓ Branch 0 taken 8949 times.
✗ Branch 1 not taken.
8949 oss << screenstate_string[ind];
1426 8949 comma = true;
1427 }
1428
1/2
✓ Branch 0 taken 7038 times.
✗ Branch 1 not taken.
7038 oss << "]";
1429 7038 }
1430
3/4
✓ Branch 0 taken 34769 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 34733 times.
34769 if(game->xstates[mi]) // ExStates
1431 {
1432
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 oss << " Ex[";
1433 36 bool comma = false;
1434
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 1152 times.
1188 for(byte fl = 0; fl < 32; ++fl)
1435 {
1436
3/4
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✓ Branch 3 taken 1110 times.
1152 if(game->xstates[mi] & (1<<fl))
1437 {
1438
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 36 times.
42 if(comma)
1439
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 oss << ", ";
1440
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 oss << int(fl);
1441 42 comma = true;
1442 42 }
1443 1152 }
1444
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 oss << "]";
1445 36 }
1446 { // ExDoors
1447
2/2
✓ Branch 0 taken 34769 times.
✓ Branch 1 taken 139076 times.
173845 for(int q = 0; q < 4; ++q)
1448 {
1449 139076 bool comma = false;
1450
3/4
✓ Branch 0 taken 139076 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 139066 times.
✓ Branch 3 taken 10 times.
139076 if(auto v = game->xdoors[mi][q])
1451 {
1452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(comma)
1453 oss << ",";
1454
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 else oss << " ExDoor";
1455
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 oss << "[" << dirstr[q];
1456
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 80 times.
90 for(int fl = 0; fl < 8; ++fl)
1457
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 18 times.
98 if(v & (1<<fl))
1458
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
18 oss << " " << int(fl);
1459
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 oss << "]";
1460 10 comma = true;
1461 10 }
1462 139076 }
1463 }
1464
2/4
✓ Branch 0 taken 34769 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 34769 times.
34769 Z_eventlog("%s\n", oss.str().c_str());
1465 34769 }
1466
1467 // set specific flag
1468 5598 void setmapflag(mapscr* scr, int32_t flag)
1469 {
1470
2/2
✓ Branch 0 taken 5585 times.
✓ Branch 1 taken 13 times.
5598 if (scr->screen >= 0x80) scr = special_warp_return_scr;
1471 5598 int mi = mapind(cur_map, scr->screen);
1472 5598 setmapflag_mi(scr, mi, flag);
1473 5598 }
1474 57 void setmapflag_homescr(int32_t flag)
1475 {
1476 57 int mi = mapind(cur_map, home_screen);
1477 57 setmapflag_mi(origin_scr, mi, flag);
1478 57 }
1479 2013 void setmapflag_mi(int32_t mi, int32_t flag)
1480 {
1481 2013 byte cscr = mi&((1<<7)-1);
1482 2013 byte cmap = (mi>>7);
1483 2013 mapscr* scr = origin_scr;
1484
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 1185 times.
2013 if (is_in_current_region(cmap, cscr))
1485 1185 scr = get_scr(cmap, cscr);
1486
1487 2013 setmapflag_mi(scr, mi, flag);
1488 2013 }
1489
1490 8448 static void log_state_change(int map, int screen, std::string action)
1491 {
1492
6/6
✓ Branch 0 taken 1904 times.
✓ Branch 1 taken 6544 times.
✓ Branch 2 taken 987 times.
✓ Branch 3 taken 917 times.
✓ Branch 4 taken 349 times.
✓ Branch 5 taken 638 times.
8448 if (is_in_current_region(map, screen) || (map == cur_map && screen == home_screen))
1493 6893 Z_eventlog("[Map %d, Screen %02X (current)] %s\n", map + 1, screen, action.c_str());
1494 else
1495 1555 Z_eventlog("[Map %d, Screen %02X] %s\n", map + 1, screen, action.c_str());
1496 8448 }
1497
1498 7668 void setmapflag_mi(mapscr* scr, int32_t mi, int32_t flag)
1499 {
1500 7668 byte cscr = mi&((1<<7)-1);
1501 7668 byte cmap = (mi>>7);
1502
1503 7668 float temp=log2((float)flag);
1504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7668 times.
7668 const char* state_string = flag>0 ? screenstate_string[(int32_t)temp] : "<Unknown>";
1505
1506
3/4
✓ Branch 0 taken 7668 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1552 times.
✓ Branch 3 taken 6116 times.
7668 if (replay_is_active() && !(game->maps[mi] & flag))
1507
1/2
✓ Branch 0 taken 6116 times.
✗ Branch 1 not taken.
6116 replay_step_comment(fmt::format("map {} scr {} flag {}", cmap, cscr, state_string));
1508 7668 game->maps[mi] |= flag;
1509
1/2
✓ Branch 0 taken 7668 times.
✗ Branch 1 not taken.
7668 log_state_change(cmap, cscr, fmt::format("State set: {}", state_string));
1510
1511
10/10
✓ Branch 0 taken 5432 times.
✓ Branch 1 taken 2236 times.
✓ Branch 2 taken 3599 times.
✓ Branch 3 taken 1833 times.
✓ Branch 4 taken 3018 times.
✓ Branch 5 taken 581 times.
✓ Branch 6 taken 2864 times.
✓ Branch 7 taken 154 times.
✓ Branch 8 taken 13 times.
✓ Branch 9 taken 2467 times.
10148 if(flag==mSECRET||flag==mITEM||flag==mSPECIALITEM||flag==mLOCKBLOCK||
1512
6/6
✓ Branch 0 taken 2817 times.
✓ Branch 1 taken 47 times.
✓ Branch 2 taken 2672 times.
✓ Branch 3 taken 145 times.
✓ Branch 4 taken 2480 times.
✓ Branch 5 taken 192 times.
2864 flag==mBOSSLOCKBLOCK||flag==mCHEST||flag==mBOSSCHEST||flag==mLOCKEDCHEST)
1513 {
1514 5201 byte nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
1515 5201 byte nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
1516
1517 5201 std::vector<int32_t> done;
1518
2/2
✓ Branch 0 taken 5086 times.
✓ Branch 1 taken 115 times.
5201 bool looped = (nmap==cmap+1 && nscr==cscr);
1519
1520
6/6
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 5149 times.
✓ Branch 2 taken 52 times.
✓ Branch 3 taken 486 times.
✓ Branch 4 taken 486 times.
✓ Branch 5 taken 5201 times.
5687 while((nmap!=0) && !looped && !(nscr>=128))
1521 {
1522
5/6
✓ Branch 0 taken 364 times.
✓ Branch 1 taken 122 times.
✓ Branch 2 taken 364 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 171 times.
✓ Branch 5 taken 193 times.
486 if((scr->nocarry&flag)!=flag && !(game->maps[((nmap-1)<<7)+nscr] & flag))
1523 {
1524
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 log_state_change(nmap, nscr, "State change carried over");
1525
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 if (replay_is_active())
1526
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 replay_step_comment(fmt::format("map {} scr {} flag {} carry", nmap, nscr, state_string));
1527
1/2
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
193 game->maps[((nmap-1)<<7)+nscr] |= flag;
1528 193 }
1529
1530 486 cmap=nmap;
1531 486 cscr=nscr;
1532 486 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
1533 486 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
1534
1535
2/2
✓ Branch 0 taken 1480 times.
✓ Branch 1 taken 486 times.
1966 for(auto it = done.begin(); it != done.end(); it++)
1536 {
1537
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 52 times.
1480 if(*it == ((nmap-1)<<7)+nscr)
1538 52 looped = true;
1539 1480 }
1540
1541
1/2
✓ Branch 0 taken 486 times.
✗ Branch 1 not taken.
486 done.push_back(((nmap-1)<<7)+nscr);
1542 }
1543 5201 }
1544 7668 }
1545
1546 void unsetmapflag_home(int32_t flag, bool anyflag)
1547 {
1548 int mi = mapind(cur_map, home_screen);
1549 unsetmapflag_mi(origin_scr, mi, flag, anyflag);
1550 }
1551
1552 void unsetmapflag(mapscr* scr, int32_t flag, bool anyflag)
1553 {
1554 if (scr->screen >= 0x80) scr = special_warp_return_scr;
1555 int mi = mapind(cur_map, scr->screen);
1556 unsetmapflag_mi(scr, mi, flag, anyflag);
1557 }
1558
1559 471 void unsetmapflag_mi(int32_t mi, int32_t flag, bool anyflag)
1560 {
1561 471 byte cscr = mi&((1<<7)-1);
1562 471 byte cmap = (mi>>7);
1563 471 mapscr* scr = origin_scr;
1564
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 11 times.
471 if (is_in_current_region(cmap, cscr))
1565 11 scr = get_scr(cmap, cscr);
1566
1567 471 unsetmapflag_mi(scr, mi, flag, anyflag);
1568 471 }
1569
1570 471 void unsetmapflag_mi(mapscr* scr, int32_t mi, int32_t flag, bool anyflag)
1571 {
1572 471 byte cscr = mi&((1<<7)-1);
1573 471 byte cmap = (mi>>7);
1574
1575
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 11 times.
471 if(anyflag)
1576 460 game->maps[mi] &= ~flag;
1577
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 else if(flag==mITEM || flag==mSPECIALITEM)
1578 {
1579 if(!(scr->flags4&fNOITEMRESET))
1580 game->maps[mi] &= ~flag;
1581 }
1582 11 else game->maps[mi] &= ~flag;
1583
1584 471 float temp=log2((float)flag);
1585
1/2
✓ Branch 0 taken 471 times.
✗ Branch 1 not taken.
471 const char* state_string = flag>0 ? screenstate_string[(int32_t)temp] : "<Unknown>";
1586
1/2
✓ Branch 0 taken 471 times.
✗ Branch 1 not taken.
471 log_state_change(cmap, cscr, fmt::format("State unset: {}", state_string));
1587
1588
5/10
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 460 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
471 if(flag==mSECRET||flag==mITEM||flag==mSPECIALITEM||flag==mLOCKBLOCK||
1589
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
11 flag==mBOSSLOCKBLOCK||flag==mCHEST||flag==mBOSSCHEST||flag==mLOCKEDCHEST)
1590 {
1591 471 byte nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
1592 471 byte nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
1593
1594 471 std::vector<int32_t> done;
1595
2/2
✓ Branch 0 taken 466 times.
✓ Branch 1 taken 5 times.
471 bool looped = (nmap==cmap+1 && nscr==cscr);
1596
1597
6/6
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 465 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 84 times.
✓ Branch 4 taken 84 times.
✓ Branch 5 taken 471 times.
555 while((nmap!=0) && !looped && !(nscr>=128))
1598 {
1599
4/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 72 times.
84 if((scr->nocarry&flag)!=flag && (game->maps[((nmap-1)<<7)+nscr] & flag))
1600 {
1601
2/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
72 log_state_change(nmap, nscr, "State change carried over");
1602
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 game->maps[((nmap-1)<<7)+nscr] &= ~flag;
1603 72 }
1604
1605 84 cmap=nmap;
1606 84 cscr=nscr;
1607 84 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
1608 84 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
1609
1610
2/2
✓ Branch 0 taken 546 times.
✓ Branch 1 taken 84 times.
630 for(std::vector<int32_t>::iterator it = done.begin(); it != done.end(); it++)
1611 {
1612
2/2
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 6 times.
546 if(*it == ((nmap-1)<<7)+nscr)
1613 6 looped = true;
1614 546 }
1615
1616
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 done.push_back(((nmap-1)<<7)+nscr);
1617 }
1618 471 }
1619 471 }
1620
1621 44020357 bool getmapflag(int32_t screen, int32_t flag)
1622 {
1623
2/2
✓ Branch 0 taken 1156193 times.
✓ Branch 1 taken 42864164 times.
44020357 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1624 44020357 return (game->maps[mi] & flag) != 0;
1625 }
1626 162043 bool getmapflag(mapscr* scr, int32_t flag)
1627 {
1628 162043 return getmapflag(scr->screen, flag);
1629 }
1630
1631 59 void setxmapflag(int32_t screen, uint32_t flag)
1632 {
1633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1634 59 setxmapflag_mi(mi, flag);
1635 59 }
1636 61 void setxmapflag_mi(int32_t mi, uint32_t flag)
1637 {
1638
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 40 times.
61 if(game->xstates[mi] & flag) return;
1639 40 byte cscr = mi&((1<<7)-1);
1640 40 byte cmap = (mi>>7);
1641
1642 40 byte temp=(byte)log2((double)flag);
1643
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 log_state_change(cmap, cscr, fmt::format("ExtraState set: {}", temp));
1644
1645 40 game->xstates[mi] |= flag;
1646 61 }
1647 void unsetxmapflag(int32_t screen, uint32_t flag)
1648 {
1649 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1650 unsetxmapflag_mi(mi, flag);
1651 }
1652 void unsetxmapflag_mi(int32_t mi, uint32_t flag)
1653 {
1654 if(!(game->xstates[mi] & flag)) return;
1655 byte cscr = mi&((1<<7)-1);
1656 byte cmap = (mi>>7);
1657 byte temp=(byte)log2((double)flag);
1658 log_state_change(cmap, cscr, fmt::format("ExtraState unset: {}", temp));
1659 game->xstates[mi] &= ~flag;
1660 }
1661 29 bool getxmapflag(int32_t screen, uint32_t flag)
1662 {
1663
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
29 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1664 29 return getxmapflag_mi(mi, flag);
1665 }
1666 469722795 bool getxmapflag_mi(int32_t mi, uint32_t flag)
1667 {
1668 469722795 return (game->xstates[mi] & flag) != 0;
1669 }
1670
1671 4 void setxdoor_mi(uint mi, uint dir, uint ind, bool state)
1672 {
1673
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
4 if(mi > game->xdoors.size() || dir > 3 || ind > 8)
1674 return;
1675
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(!(game->xdoors[mi][dir] & (1<<ind)) == !state)
1676 return;
1677
1678
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 SETFLAG(game->xdoors[mi][dir], 1<<ind, state);
1679
1680 4 int cscr = mi % MAPSCRSNORMAL;
1681 4 int cmap = mi / MAPSCRSNORMAL;
1682
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (state)
1683
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 log_state_change(cmap, cscr, fmt::format("ExDoor[{}][{}] set", dirstr[dir], ind));
1684 else
1685 log_state_change(cmap, cscr, fmt::format("ExDoor[{}][{}] unset", dirstr[dir], ind));
1686 4 }
1687 469722765 bool getxdoor_mi(uint mi, uint dir, uint ind)
1688 {
1689
3/6
✓ Branch 0 taken 469722765 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 469722765 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 469722765 times.
469722765 if(mi >= game->xdoors.size() || dir >= 4 || ind >= 8)
1690 return false;
1691 469722765 return (game->xdoors[mi][dir] & (1<<ind));
1692 469722765 }
1693 13 bool getxdoor(int32_t screen, uint dir, uint ind)
1694 {
1695 13 int mi = mapind(cur_map, screen);
1696 13 return getxdoor_mi(mi,dir,ind);
1697 }
1698
1699 397 void set_doorstate_mi(uint mi, uint dir)
1700 {
1701
1/2
✓ Branch 0 taken 397 times.
✗ Branch 1 not taken.
397 if(dir >= 4)
1702 return;
1703 397 setmapflag_mi(mi, mDOOR_UP << dir);
1704
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 396 times.
397 if(auto di = nextscr_mi(mi, dir))
1705 396 setmapflag_mi(*di, mDOOR_UP << oppositeDir[dir]);
1706 397 }
1707 397 void set_doorstate(uint screen, uint dir)
1708 {
1709 397 int mi = mapind(cur_map, screen);
1710 397 set_doorstate_mi(mi, dir);
1711 397 }
1712
1713 2 void set_xdoorstate_mi(uint mi, uint dir, uint ind, bool state)
1714 {
1715
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 if(mi >= game->xdoors.size() || dir >= 4 || ind >= 8)
1716 return;
1717 2 setxdoor_mi(mi, dir, ind, state);
1718
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(auto di = nextscr_mi(mi, dir))
1719 2 setxdoor_mi(*di, oppositeDir[dir], ind, state);
1720 2 }
1721
1722 2 void set_xdoorstate(int32_t screen,uint dir, uint ind, bool state)
1723 {
1724 2 int mi = mapind(cur_map, screen);
1725 2 set_xdoorstate_mi(mi, dir, ind, state);
1726 2 }
1727
1728 57 int32_t WARPCODE(int32_t dmap,int32_t screen,int32_t dw)
1729 // returns: -1 = not a warp screen
1730 // 0+ = warp screen code ( high byte=dmap, low byte=scr )
1731 {
1732 57 const mapscr *scr = get_canonical_scr(DMaps[dmap].map, screen);
1733
1734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if(scr->room!=rWARP)
1735 return -1;
1736
1737 57 int32_t ring=scr->catchall;
1738 57 int32_t size=QMisc.warp[ring].size;
1739
1740
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 if(size==0)
1741 return -2;
1742
1743 57 int32_t index=-1;
1744
1745
2/2
✓ Branch 0 taken 289 times.
✓ Branch 1 taken 57 times.
346 for(int32_t i=0; i<size; i++)
1746
6/6
✓ Branch 0 taken 230 times.
✓ Branch 1 taken 59 times.
✓ Branch 2 taken 173 times.
✓ Branch 3 taken 57 times.
✓ Branch 4 taken 173 times.
✓ Branch 5 taken 57 times.
289 if(dmap==QMisc.warp[ring].dmap[i] && screen==
1747 346 (QMisc.warp[ring].scr[i] + DMaps[dmap].xoff))
1748 57 index=i;
1749
1750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if(index==-1)
1751 return -3;
1752
1753 57 index = (index+dw)%size;
1754 57 return (QMisc.warp[ring].dmap[index] << 8) + QMisc.warp[ring].scr[index];
1755 57 }
1756
1757 14724666 void update_combo_cycling()
1758 {
1759 14724666 auto& combo_cache = combo_caches::can_cycle;
1760
1761 static int32_t newdata[176];
1762 static int32_t newcset[176];
1763 static bool initialized=false;
1764
1765 // Just a simple bit of optimization
1766
2/2
✓ Branch 0 taken 14724364 times.
✓ Branch 1 taken 302 times.
14724666 if(!initialized)
1767 {
1768
2/2
✓ Branch 0 taken 53152 times.
✓ Branch 1 taken 302 times.
53454 for(int32_t i=0; i<176; i++)
1769 {
1770 53152 newdata[i]=-1;
1771 53152 newcset[i]=-1;
1772 53152 }
1773
1774 302 initialized=true;
1775 302 }
1776
1777 14724666 std::set<uint16_t> restartanim;
1778
1779
1/2
✓ Branch 0 taken 14724666 times.
✗ Branch 1 not taken.
29838700 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
1780 15114034 int screen = scr->screen;
1781 int32_t x;
1782
1783
2/2
✓ Branch 0 taken 2660069984 times.
✓ Branch 1 taken 15114034 times.
2675184018 for(int32_t i=0; i<176; i++)
1784 {
1785 2660069984 x=scr->data[i];
1786 2660069984 auto& mini_cmb = combo_cache.minis[x];
1787
2/2
✓ Branch 0 taken 3273932 times.
✓ Branch 1 taken 2656796052 times.
2660069984 if (!mini_cmb.can_cycle)
1788 2656796052 continue;
1789
1790 3273932 newcombo const& cmb = combobuf[x];
1791
1792 //time to restart
1793
4/4
✓ Branch 0 taken 902694 times.
✓ Branch 1 taken 2371238 times.
✓ Branch 2 taken 474434 times.
✓ Branch 3 taken 428260 times.
3273932 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1794 {
1795 428260 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 428260 times.
428260 auto c = cycle_under ? scr->undercombo : cmb.nextcombo;
1797 428260 newdata[i] = c;
1798
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 428240 times.
428260 if(!(cmb.animflags & AF_CYCLENOCSET))
1799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 428240 times.
428240 newcset[i] = cycle_under ? scr->undercset : cmb.nextcset;
1800
1801
2/2
✓ Branch 0 taken 427216 times.
✓ Branch 1 taken 1044 times.
428260 if(combobuf[c].animflags & AF_CYCLE)
1802 {
1803 1044 restartanim.insert(c);
1804 1044 }
1805 428260 }
1806 3273932 }
1807
1808 15114034 int rpos_base = (int)POS_TO_RPOS(0, region_scr_x, region_scr_y);
1809
2/2
✓ Branch 0 taken 2660069984 times.
✓ Branch 1 taken 15114034 times.
2675184018 for(int32_t i=0; i<176; i++)
1810 {
1811
2/2
✓ Branch 0 taken 428260 times.
✓ Branch 1 taken 2659641724 times.
2660069984 if(newdata[i]==-1)
1812 2659641724 continue;
1813
1814 428260 rpos_t rpos = (rpos_t)(rpos_base + i);
1815 428260 rpos_handle_t rpos_handle = {scr, screen, 0, rpos, i};
1816 428260 screen_combo_modify_preroutine(rpos_handle);
1817 428260 scr->data[i]=newdata[i];
1818
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 428240 times.
428260 if(newcset[i]>-1)
1819 428240 scr->cset[i]=newcset[i];
1820 428260 screen_combo_modify_postroutine(rpos_handle);
1821
1822 428260 newdata[i]=-1;
1823 428260 newcset[i]=-1;
1824 428260 }
1825
1826 15114034 word c = scr->numFFC();
1827
2/2
✓ Branch 0 taken 15114034 times.
✓ Branch 1 taken 451712053 times.
466826087 for(word i=0; i<c; i++)
1828 {
1829 451712053 ffcdata& ffc = scr->ffcs[i];
1830 451712053 auto& mini_cmb = combo_cache.minis[ffc.data];
1831
2/2
✓ Branch 0 taken 4173 times.
✓ Branch 1 taken 451707880 times.
451712053 if (!mini_cmb.can_cycle)
1832 451707880 continue;
1833
1834 4173 newcombo const& cmb = combobuf[ffc.data];
1835
1836 //time to restart
1837
4/4
✓ Branch 0 taken 611 times.
✓ Branch 1 taken 3562 times.
✓ Branch 2 taken 503 times.
✓ Branch 3 taken 108 times.
4173 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1838 {
1839 108 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 auto c = cycle_under ? scr->undercombo : cmb.nextcombo;
1841 108 zc_ffc_set(ffc, c);
1842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!(cmb.animflags & AF_CYCLENOCSET))
1843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 ffc.cset = cycle_under ? scr->undercset : cmb.nextcset;
1844
1845
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 60 times.
108 if(combobuf[ffc.data].animflags & AF_CYCLE)
1846 {
1847 60 restartanim.insert(ffc.data);
1848 60 }
1849 108 }
1850 4173 }
1851
1852
2/2
✓ Branch 0 taken 8417968 times.
✓ Branch 1 taken 6696066 times.
15114034 if(get_qr(qr_CMBCYCLELAYERS))
1853 {
1854
2/2
✓ Branch 0 taken 40176396 times.
✓ Branch 1 taken 6696066 times.
46872462 for(int32_t j=1; j<=6; j++)
1855 {
1856 40176396 mapscr* layer_scr = get_scr_layer_valid(screen, j);
1857
2/2
✓ Branch 0 taken 10834542 times.
✓ Branch 1 taken 29341854 times.
40176396 if (!layer_scr)
1858 29341854 continue;
1859
1860
2/2
✓ Branch 0 taken 1906879392 times.
✓ Branch 1 taken 10834542 times.
1917713934 for(int32_t i=0; i<176; i++)
1861 {
1862 1906879392 x=layer_scr->data[i];
1863 1906879392 auto& mini_cmb = combo_cache.minis[x];
1864
2/2
✓ Branch 0 taken 2230121 times.
✓ Branch 1 taken 1904649271 times.
1906879392 if (!mini_cmb.can_cycle)
1865 1904649271 continue;
1866
1867 2230121 newcombo const& cmb = combobuf[x];
1868
1869 //time to restart
1870
4/4
✓ Branch 0 taken 48392 times.
✓ Branch 1 taken 2181729 times.
✓ Branch 2 taken 37470 times.
✓ Branch 3 taken 10922 times.
2230121 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1871 {
1872 10922 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10922 times.
10922 auto c = cycle_under ? layer_scr->undercombo : cmb.nextcombo;
1874 10922 newdata[i] = c;
1875
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 10864 times.
10922 if(!(cmb.animflags & AF_CYCLENOCSET))
1876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10864 times.
10864 newcset[i] = cycle_under ? layer_scr->undercset : cmb.nextcset;
1877 58 else newcset[i] = layer_scr->cset[i];
1878
1879
2/2
✓ Branch 0 taken 947 times.
✓ Branch 1 taken 9975 times.
10922 if(combobuf[c].animflags & AF_CYCLE)
1880 {
1881 9975 restartanim.insert(c);
1882 9975 }
1883 10922 }
1884 2230121 }
1885
1886
2/2
✓ Branch 0 taken 1906879392 times.
✓ Branch 1 taken 10834542 times.
1917713934 for (int32_t i=0; i<176; i++)
1887 {
1888
2/2
✓ Branch 0 taken 1906868470 times.
✓ Branch 1 taken 10922 times.
1906879392 if(newdata[i]!=-1)
1889 {
1890 10922 layer_scr->data[i]=newdata[i];
1891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10922 times.
10922 if(newcset[i]>-1)
1892 10922 layer_scr->cset[i]=newcset[i];
1893 10922 newdata[i]=-1;
1894 10922 newcset[i]=-1;
1895 10922 }
1896 1906879392 }
1897 10834542 }
1898 6696066 }
1899 15114034 });
1900
1901
2/2
✓ Branch 0 taken 14724666 times.
✓ Branch 1 taken 2657 times.
14727323 for (auto i : restartanim)
1902 {
1903 2657 combobuf[i].tile = combobuf[i].o_tile;
1904 2657 combobuf[i].cur_frame=0;
1905 2657 combobuf[i].aclk = 0;
1906
1/2
✓ Branch 0 taken 2657 times.
✗ Branch 1 not taken.
2657 combo_caches::drawing.refresh(i);
1907 }
1908 14724666 }
1909
1910 1205157344 bool iswater_type(int32_t type)
1911 {
1912 // return type==cOLD_WATER || type==cSWIMWARP || type==cDIVEWARP || type==cDIVEWARPB || type==cDIVEWARPC || type==cDIVEWARPD || type==cSWIMWARPB || type==cSWIMWARPC || type==cSWIMWARPD;
1913 1205157344 return (combo_class_buf[type].water!=0);
1914 }
1915
1916 bool iswater(int32_t combo)
1917 {
1918 return iswater_type(combobuf[combo].type) && !DRIEDLAKE;
1919 }
1920 1135408 int32_t iswaterexzq(int32_t combo, int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck)
1921 {
1922 1135408 return iswaterex(combo, map, screen, layer, x, y, secrets, fullcheck, LayerCheck);
1923 }
1924
1925 // (x, y) are world coordinates
1926 58729290 int32_t iswaterex_z3(int32_t combo, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck, bool ShallowCheck, bool hero, optional<combined_handle_t>* out_handle)
1927 {
1928
8/8
✓ Branch 0 taken 58683255 times.
✓ Branch 1 taken 46035 times.
✓ Branch 2 taken 58642971 times.
✓ Branch 3 taken 40284 times.
✓ Branch 4 taken 58576477 times.
✓ Branch 5 taken 66494 times.
✓ Branch 6 taken 59358 times.
✓ Branch 7 taken 58517119 times.
58729290 if (x<0 || x>=world_w || y<0 || y>=world_h)
1929 212171 return false;
1930
1931 58517119 return iswaterex(combo, cur_map, cur_screen, layer, x, y, secrets, fullcheck, LayerCheck, ShallowCheck, hero, out_handle);
1932 58729290 }
1933
1934 97358841 int32_t iswaterex(int32_t combo, int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck, bool ShallowCheck, bool hero, optional<combined_handle_t>* out_handle)
1935 {
1936 DCHECK_LAYER_NEG1_INDEX(layer);
1937 //Honestly, fullcheck is kinda useless... I made this function back when I thought it was checking the entire combo and not just a glorified x/y value.
1938 //Fullcheck makes no sense to ever be on, but hey I guess it's here in case you ever need it...
1939
1940 //Oh hey, Zoras might actually need it. Nevermind, this had a use!
1941
2/2
✓ Branch 0 taken 57580095 times.
✓ Branch 1 taken 39778746 times.
97358841 if (get_qr(qr_SMARTER_WATER))
1942 {
1943
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 57580095 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
57580095 if (DRIEDLAKE) return 0;
1944
5/6
✓ Branch 0 taken 19616230 times.
✓ Branch 1 taken 37963865 times.
✓ Branch 2 taken 6518562 times.
✓ Branch 3 taken 13097668 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6518562 times.
57580095 if (LayerCheck && (get_qr(qr_WATER_ON_LAYER_1) || get_qr(qr_WATER_ON_LAYER_2))) //LayerCheck is a bit dumber, but it lets me add this QR without having to replace all calls, again.
1945 {
1946
2/2
✓ Branch 0 taken 37946344 times.
✓ Branch 1 taken 12424338 times.
50370682 for (int32_t m = layer; m <= 1; m++)
1947 {
1948
5/6
✓ Branch 0 taken 24848676 times.
✓ Branch 1 taken 13097668 times.
✓ Branch 2 taken 12424338 times.
✓ Branch 3 taken 12424338 times.
✓ Branch 4 taken 12424338 times.
✗ Branch 5 not taken.
50370682 if (m < 0 || m == 0 && get_qr(qr_WATER_ON_LAYER_1)
1949
1/2
✓ Branch 0 taken 12424338 times.
✗ Branch 1 not taken.
24848676 || m == 1 && get_qr(qr_WATER_ON_LAYER_2))
1950 {
1951 37946344 int32_t checkwater = iswaterex(combo, map, screen, m, x, y, secrets, fullcheck, false, ShallowCheck);
1952
2/2
✓ Branch 0 taken 37273014 times.
✓ Branch 1 taken 673330 times.
37946344 if (checkwater > 0)
1953 {
1954
2/2
✓ Branch 0 taken 673272 times.
✓ Branch 1 taken 58 times.
673330 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(x, y, m+1);
1955 673330 return checkwater;
1956 }
1957 37273014 }
1958 37273014 }
1959 12424338 return 0;
1960 }
1961 else
1962 {
1963
2/2
✓ Branch 0 taken 44497100 times.
✓ Branch 1 taken 42293999 times.
86791099 for(int32_t i=(fullcheck?3:0); i>=0; i--)
1964 {
1965 44497100 int32_t tx2=((i&2)<<2)+x;
1966 44497100 int32_t ty2=((i&1)<<3)+y;
1967 44497100 int32_t b = i; //Originally b was not needed and I read off i, but then I added the boolean for fullcheck.
1968 //In which case it's just easier to change b if fullcheck is false instead of changing i and potentially screwing up the for loop.
1969
2/2
✓ Branch 0 taken 21673 times.
✓ Branch 1 taken 44475427 times.
44497100 if (!fullcheck)
1970 {
1971 44475427 tx2 = x;
1972 44475427 ty2 = y;
1973
2/2
✓ Branch 0 taken 24969970 times.
✓ Branch 1 taken 19505457 times.
44475427 if(tx2&8) b+=2;
1974
2/2
✓ Branch 0 taken 20628027 times.
✓ Branch 1 taken 23847400 times.
44475427 if(ty2&8) b+=1;
1975 44475427 }
1976
2/2
✓ Branch 0 taken 95107640 times.
✓ Branch 1 taken 43638593 times.
138746233 for (int32_t m = layer; m <= 1; m++)
1977 {
1978 95107640 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2, true)];
1979
2/2
✓ Branch 0 taken 17735727 times.
✓ Branch 1 taken 77371913 times.
95107640 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1980 {
1981
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 17735727 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
17735727 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<b)))
1982 {
1983 return 0;
1984 }
1985 17735727 }
1986 else
1987 {
1988
4/4
✓ Branch 0 taken 188663 times.
✓ Branch 1 taken 77183250 times.
✓ Branch 2 taken 51152 times.
✓ Branch 3 taken 137511 times.
77371913 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<b)))
1989 {
1990 137511 return 0;
1991 }
1992 }
1993
2/2
✓ Branch 0 taken 17735727 times.
✓ Branch 1 taken 77234402 times.
94970129 if (get_qr(qr_NO_SOLID_SWIM))
1994 {
1995
8/14
✓ Branch 0 taken 51152 times.
✓ Branch 1 taken 77183250 times.
✓ Branch 2 taken 51152 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 720996 times.
✓ Branch 5 taken 76462254 times.
✓ Branch 6 taken 3461 times.
✓ Branch 7 taken 717535 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 3461 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
77234402 if ((cmb.type != cBRIDGE || (!get_qr(qr_OLD_BRIDGE_COMBOS) && !(cmb.walk&(0x10<<b)))) && (cmb.walk&(1<<b)) && !((cmb.usrflags&cflag4) && cmb.type == cWATER && (cmb.walk&(0x10<<b)) && ShallowCheck))
1996 {
1997 720996 return 0;
1998 }
1999 76513406 }
2000
3/6
✓ Branch 0 taken 320336 times.
✓ Branch 1 taken 93928797 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 320336 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
94249133 if (iswater_type(cmb.type) && (cmb.walk&(1<<b)) && ((cmb.usrflags&cflag3) || (cmb.usrflags&cflag4)
2001 || (hero && current_item(itype_flippers) < cmb.attribytes[0])
2002 || (hero && ((cmb.usrflags&cflag1) && !(itemsbuf[current_item_id(itype_flippers)].flags & item_flag3)))))
2003 {
2004 if (!(ShallowCheck && (cmb.walk&(1<<b)) && (cmb.usrflags&cflag4))) return 0;
2005 }
2006 94249133 }
2007
2008 131503863 auto found_ffc_not_water = find_ffc([&](const ffc_handle_t& ffc_handle) {
2009
2/2
✓ Branch 0 taken 87337405 times.
✓ Branch 1 taken 527865 times.
87865270 if (ffcIsAt(ffc_handle, tx2, ty2))
2010 {
2011 527865 auto ty = ffc_handle.ctype();
2012
4/6
✓ Branch 0 taken 527865 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144225 times.
✓ Branch 3 taken 383640 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 144225 times.
527865 if(!combo_class_buf[ty].water && !(ShallowCheck && ty == cSHALLOWWATER))
2013 527865 return true;
2014 }
2015
2016 87337405 return false;
2017 87865270 });
2018
2/2
✓ Branch 0 taken 43110728 times.
✓ Branch 1 taken 527865 times.
43638593 if (found_ffc_not_water) return 0;
2019
2020
2/2
✓ Branch 0 taken 14673 times.
✓ Branch 1 taken 43096055 times.
43110728 if(!i)
2021 {
2022 128109539 auto found_ffc_water = find_ffc([&](const ffc_handle_t& ffc_handle) {
2023
1/2
✓ Branch 0 taken 85013484 times.
✗ Branch 1 not taken.
85013484 if (ffcIsAt(ffc_handle, tx2, ty2))
2024 {
2025 auto ty = ffc_handle.ctype();
2026 if(combo_class_buf[ty].water || (ShallowCheck && ty == cSHALLOWWATER))
2027 return true;
2028 }
2029
2030 85013484 return false;
2031 85013484 });
2032
1/2
✓ Branch 0 taken 43096055 times.
✗ Branch 1 not taken.
43096055 if (found_ffc_water)
2033 {
2034 if(out_handle) *out_handle = *found_ffc_water;
2035 return found_ffc_water->data();
2036 }
2037 43096055 }
2038
2039 43110728 int32_t checkcombo = MAPCOMBO3(map, screen, layer, tx2, ty2, secrets);
2040
2/2
✓ Branch 0 taken 43066234 times.
✓ Branch 1 taken 44494 times.
43110728 if (!(combobuf[checkcombo].walk&(1<<(b+4)))) return 0;
2041
7/12
✓ Branch 0 taken 42785629 times.
✓ Branch 1 taken 280605 times.
✓ Branch 2 taken 10876747 times.
✓ Branch 3 taken 31908882 times.
✓ Branch 4 taken 10398563 times.
✓ Branch 5 taken 478184 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 10398563 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
43066234 if (iswater_type(combobuf[checkcombo].type)||(ShallowCheck && (combobuf[checkcombo].type == cSHALLOWWATER || (iswater_type(combobuf[checkcombo].type) && (combobuf[checkcombo].walk&(1<<b)) && (combobuf[checkcombo].usrflags&cflag4)))))
2042 {
2043
2/2
✓ Branch 0 taken 1227 times.
✓ Branch 1 taken 757562 times.
758789 if (i == 0)
2044 {
2045
2/2
✓ Branch 0 taken 757553 times.
✓ Branch 1 taken 9 times.
757562 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(tx2, ty2, layer+1);
2046 757562 return checkcombo;
2047 }
2048 1227 }
2049 42308672 }
2050 42293999 return 0;
2051 }
2052 }
2053 else
2054 {
2055 39778746 int32_t b = 0;
2056
2/2
✓ Branch 0 taken 20595943 times.
✓ Branch 1 taken 19182803 times.
39778746 if(x&8) b+=2;
2057
2/2
✓ Branch 0 taken 15427119 times.
✓ Branch 1 taken 24351627 times.
39778746 if(y&8) b+=1;
2058
1/2
✓ Branch 0 taken 39778746 times.
✗ Branch 1 not taken.
39778746 if (get_qr(qr_NO_SOLID_SWIM))
2059 {
2060 if (combobuf[combo].walk&(1<<b))
2061 {
2062 return 0;
2063 }
2064 }
2065
1/2
✓ Branch 0 taken 39778746 times.
✗ Branch 1 not taken.
39778746 if (!(combobuf[combo].walk&(1<<(b+4)))) return 0;
2066
8/8
✓ Branch 0 taken 38084006 times.
✓ Branch 1 taken 1694740 times.
✓ Branch 2 taken 167945 times.
✓ Branch 3 taken 37916061 times.
✓ Branch 4 taken 2129 times.
✓ Branch 5 taken 1778446 times.
✓ Branch 6 taken 163774 times.
✓ Branch 7 taken 161691 times.
39778746 if((iswater_type(combobuf[combo].type) || (ShallowCheck && combobuf[combo].type == cSHALLOWWATER)) && !DRIEDLAKE)
2067 {
2068
2/2
✓ Branch 0 taken 1940107 times.
✓ Branch 1 taken 30 times.
1940137 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(x, y, 0); //NOTE: This is only correct assuming 'combo' is 'MAPCOMBO(x,y)'
2069 1940137 return combo;
2070 }
2071 38079835 return 0;
2072 }
2073 97600067 }
2074
2075 326 bool isdamage_type(int32_t type)
2076 {
2077
1/2
✓ Branch 0 taken 326 times.
✗ Branch 1 not taken.
326 switch(type)
2078 {
2079 case cDAMAGE1: case cDAMAGE2: case cDAMAGE3: case cDAMAGE4:
2080 case cDAMAGE5: case cDAMAGE6: case cDAMAGE7:
2081 return true;
2082 }
2083 326 return false;
2084 326 }
2085
2086 2555171182 bool ispitfall_type(int32_t type)
2087 {
2088 2555171182 return combo_class_buf[type].pit != 0;
2089 }
2090
2091 2555171182 bool ispitfall(int32_t combo)
2092 {
2093 2555171182 return ispitfall_type(combobuf[combo].type);
2094 }
2095
2096 276137989 bool ispitfall(int32_t x, int32_t y)
2097 {
2098
2/2
✓ Branch 0 taken 1454897 times.
✓ Branch 1 taken 274683092 times.
276137989 if(int32_t c = MAPFFCOMBO(x,y))
2099 {
2100 1454897 return ispitfall(c) ? true : false;
2101 }
2102 274683092 int32_t c = MAPCOMBOL(2,x,y);
2103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 274683092 times.
274683092 if(ispitfall(c)) return true;
2104
2/2
✓ Branch 0 taken 261538823 times.
✓ Branch 1 taken 13144269 times.
274683092 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2105 {
2106
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 261538823 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
261538823 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1)) return false;
2107 261538823 }
2108 else
2109 {
2110
3/4
✓ Branch 0 taken 3534 times.
✓ Branch 1 taken 13140735 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3534 times.
13144269 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1)) return false;
2111 }
2112 274679558 c = MAPCOMBOL(1,x,y);
2113
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 274679534 times.
274679558 if(ispitfall(c)) return true;
2114
2115
2/2
✓ Branch 0 taken 261538823 times.
✓ Branch 1 taken 13140711 times.
274679534 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2116 {
2117
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 261538823 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
261538823 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0)) return false;
2118 261538823 }
2119 else
2120 {
2121
4/4
✓ Branch 0 taken 13072 times.
✓ Branch 1 taken 13127639 times.
✓ Branch 2 taken 8777 times.
✓ Branch 3 taken 4295 times.
13140711 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0)) return false;
2122 }
2123 274670757 c = MAPCOMBO(x,y);
2124
2/2
✓ Branch 0 taken 70766 times.
✓ Branch 1 taken 274599991 times.
274670757 if(ispitfall(c)) return true;
2125 274599991 return false;
2126 276137989 }
2127
2128 582813593 int32_t getpitfall(int32_t x, int32_t y) //Return the highest-layer active pit combo at the given position
2129 {
2130
2/2
✓ Branch 0 taken 9280299 times.
✓ Branch 1 taken 573533294 times.
582813593 if(int32_t c = MAPFFCOMBO(x,y))
2131 {
2132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9280299 times.
9280299 return ispitfall(c) ? c : 0;
2133 }
2134 573533294 int32_t c = MAPCOMBOL(2,x,y);
2135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 573533294 times.
573533294 if(ispitfall(c)) return c;
2136
2137
2/2
✓ Branch 0 taken 529770294 times.
✓ Branch 1 taken 43763000 times.
573533294 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2138 {
2139
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 529770294 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
529770294 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1)) return 0;
2140 529770294 }
2141 else
2142 {
2143
3/4
✓ Branch 0 taken 46726 times.
✓ Branch 1 taken 43716274 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 46726 times.
43763000 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1)) return 0;
2144 }
2145 573486568 c = MAPCOMBOL(1,x,y);
2146
2/2
✓ Branch 0 taken 278 times.
✓ Branch 1 taken 573486290 times.
573486568 if(ispitfall(c)) return c;
2147
2148
2/2
✓ Branch 0 taken 529770294 times.
✓ Branch 1 taken 43715996 times.
573486290 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2149 {
2150
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 529770294 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
529770294 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0)) return 0;
2151 529770294 }
2152 else
2153 {
2154
4/4
✓ Branch 0 taken 144357 times.
✓ Branch 1 taken 43571639 times.
✓ Branch 2 taken 103729 times.
✓ Branch 3 taken 40628 times.
43715996 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0)) return 0;
2155 }
2156 573382561 c = MAPCOMBO(x,y);
2157
2/2
✓ Branch 0 taken 177872 times.
✓ Branch 1 taken 573204689 times.
573382561 if(ispitfall(c)) return c;
2158 573204689 return 0;
2159 582813593 }
2160 52 optional<combined_handle_t> get_pitfall_handle(int32_t x, int32_t y) //Return the highest-layer active pit combo handle at the given position
2161 {
2162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
52 if(int32_t c = MAPFFCOMBO(x,y))
2163 {
2164 return ispitfall(c) ? getFFCAt(x,y) : nullopt;
2165 }
2166 52 int32_t c = MAPCOMBOL(2,x,y);
2167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
52 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 2);
2168
2169
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 46 times.
52 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2170 {
2171
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1))
2172 return nullopt;
2173 6 }
2174 else
2175 {
2176
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1))
2177 return nullopt;
2178 }
2179 52 c = MAPCOMBOL(1,x,y);
2180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
52 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 1);
2181
2182
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 46 times.
52 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2183 {
2184
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0))
2185 return nullopt;
2186 6 }
2187 else
2188 {
2189
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0))
2190 return nullopt;
2191 }
2192 52 c = MAPCOMBO(x,y);
2193
1/2
✓ Branch 0 taken 52 times.
✗ Branch 1 not taken.
52 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 0);
2194 return nullopt;
2195 52 }
2196 5324943 bool check_icy(newcombo const& cmb, int type)
2197 {
2198
1/2
✓ Branch 0 taken 5324943 times.
✗ Branch 1 not taken.
5324943 if(cmb.type != cICY)
2199 5324943 return false;
2200 switch(type)
2201 {
2202 case ICY_BLOCK:
2203 return cmb.usrflags&cflag1;
2204 case ICY_PLAYER:
2205 return cmb.usrflags&cflag2;
2206 }
2207 return false;
2208 5324943 }
2209 1775528 int get_icy(int x, int y, int type)
2210 {
2211 1775528 int32_t c = MAPCOMBOL(2,x,y);
2212
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1775528 times.
1775528 if(check_icy(combobuf[c], type)) return c;
2213
2214 1775528 int screen = get_screen_for_world_xy(x, y);
2215
2216 1775528 mapscr* scr = get_scr_layer_valid(screen, 2);
2217
2/2
✓ Branch 0 taken 430765 times.
✓ Branch 1 taken 1344763 times.
1775528 if (scr)
2218 {
2219
2/2
✓ Branch 0 taken 516 times.
✓ Branch 1 taken 1344247 times.
1344763 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2220 {
2221
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 516 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
516 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1, scr)) return 0;
2222 516 }
2223 else
2224 {
2225
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1344247 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1344247 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1, scr)) return 0;
2226 }
2227 1344763 }
2228 1775528 c = MAPCOMBOL(1,x,y);
2229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1775528 times.
1775528 if(check_icy(combobuf[c], type)) return c;
2230
2231 1775528 scr = get_scr_layer_valid(screen, 1);
2232
2/2
✓ Branch 0 taken 73608 times.
✓ Branch 1 taken 1701920 times.
1775528 if (scr)
2233 {
2234
2/2
✓ Branch 0 taken 1934 times.
✓ Branch 1 taken 1699986 times.
1701920 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2235 {
2236
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1934 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1934 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1, scr)) return 0;
2237 1934 }
2238 else
2239 {
2240
3/4
✓ Branch 0 taken 1641 times.
✓ Branch 1 taken 1698345 times.
✓ Branch 2 taken 1641 times.
✗ Branch 3 not taken.
1699986 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1, scr)) return 0;
2241 }
2242 1700279 }
2243 1773887 c = MAPCOMBO(x,y);
2244
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1773887 times.
1773887 if(check_icy(combobuf[c], type)) return c;
2245 1773887 return 0;
2246 1775528 }
2247
2248 12997712 static bool checkSV(int32_t x, int32_t y, int32_t flag)
2249 {
2250
8/8
✓ Branch 0 taken 12990914 times.
✓ Branch 1 taken 6798 times.
✓ Branch 2 taken 12982048 times.
✓ Branch 3 taken 8866 times.
✓ Branch 4 taken 12970416 times.
✓ Branch 5 taken 11632 times.
✓ Branch 6 taken 428348 times.
✓ Branch 7 taken 12542068 times.
12997712 if(x<0 || x>=world_w || y<0 || y>=world_h)
2251 455644 return false;
2252
2253 12542068 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, 0);
2254
2/4
✓ Branch 0 taken 12542068 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12542068 times.
12542068 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2255 return true;
2256
2257 12542068 change_rpos_handle_layer(rpos_handle, 1);
2258
2/2
✓ Branch 0 taken 7541194 times.
✓ Branch 1 taken 5000874 times.
12542068 if (rpos_handle.scr->is_valid())
2259
3/4
✓ Branch 0 taken 5000874 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2403 times.
✓ Branch 3 taken 4998471 times.
5000874 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2260 2403 return true;
2261
2262 12539665 change_rpos_handle_layer(rpos_handle, 2);
2263
2/2
✓ Branch 0 taken 10825828 times.
✓ Branch 1 taken 1713837 times.
12539665 if (rpos_handle.scr->is_valid())
2264
2/4
✓ Branch 0 taken 1713837 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1713837 times.
1713837 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2265 return true;
2266
2267 12539665 return false;
2268 12997712 }
2269
2270 6563000 bool isSVLadder(int32_t x, int32_t y)
2271 {
2272 6563000 return checkSV(x, y, mfSIDEVIEWLADDER);
2273 }
2274
2275 6434712 bool isSVPlatform(int32_t x, int32_t y)
2276 {
2277 6434712 return checkSV(x, y, mfSIDEVIEWPLATFORM);
2278 }
2279
2280 6434712 bool checkSVLadderPlatform(int32_t x, int32_t y)
2281 {
2282
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6434712 times.
✓ Branch 2 taken 6433289 times.
✓ Branch 3 taken 1423 times.
6434712 return isSVPlatform(x,y) || (isSVLadder(x,y) && !isSVLadder(x,y-16));
2283 }
2284
2285 1637 bool isstepable(int32_t combo) //can use ladder on it
2286 {
2287
2/2
✓ Branch 0 taken 1631 times.
✓ Branch 1 taken 6 times.
1637 if(combo_class_buf[combobuf[combo].type].ladder_pass) return true;
2288
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(combo_class_buf[combobuf[combo].type].pit)
2289 {
2290 if(combobuf[combo].usrflags&cflag4)
2291 {
2292 int32_t ldrid = current_item_id(itype_ladder);
2293 return (ldrid > -1 && itemsbuf[ldrid].flags & item_flag1);
2294 }
2295 }
2296 6 return false;
2297 1637 }
2298
2299 32780 bool isHSGrabbable(newcombo const& cmb)
2300 {
2301
2/2
✓ Branch 0 taken 373 times.
✓ Branch 1 taken 32407 times.
32780 if(cmb.type == cHSGRAB) return true;
2302 32407 return cmb.genflags & cflag1;
2303 32780 }
2304
2305 954 bool isSwitchHookable(newcombo const& cmb)
2306 {
2307
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 822 times.
954 if(cmb.type == cSWITCHHOOK) return true;
2308 822 return cmb.genflags & cflag2;
2309 954 }
2310
2311 61401 bool check_hshot(int32_t layer, int32_t x, int32_t y, bool switchhook, rpos_t *out_rpos, ffcdata **out_ffc)
2312 {
2313 61401 rpos_t cpos = rpos_t::None;
2314
2/2
✓ Branch 0 taken 64592 times.
✓ Branch 1 taken 125993 times.
61401 if(out_rpos)
2315 {
2316 125993 int32_t id = MAPCOMBO2(layer-1,x,y);
2317
2/2
✓ Branch 0 taken 28634 times.
✓ Branch 1 taken 97359 times.
125993 if(id > 0)
2318 {
2319 97359 newcombo const& cmb = combobuf[id];
2320
4/4
✓ Branch 0 taken 32738 times.
✓ Branch 1 taken 64621 times.
✓ Branch 2 taken 32296 times.
✓ Branch 3 taken 32325 times.
97359 cpos = (switchhook ? isSwitchHookable(cmb) : isHSGrabbable(cmb)) ? COMBOPOS_REGION(x,y) : rpos_t::None;
2321 32767 }
2322 61401 }
2323
2324 125993 ffcdata* ffc = nullptr;
2325
4/4
✓ Branch 0 taken 28389 times.
✓ Branch 1 taken 97604 times.
✓ Branch 2 taken 24996 times.
✓ Branch 3 taken 3393 times.
125993 if (out_ffc && !get_qr(qr_OLD_FFC_FUNCTIONALITY))
2326 {
2327 10361 for_some_ffcs([&](const ffc_handle_t& ffc_handle) {
2328
2/2
✓ Branch 0 taken 6853 times.
✓ Branch 1 taken 115 times.
6968 if (ffcIsAt(ffc_handle, x, y))
2329 {
2330 115 auto& cmb = ffc_handle.combo();
2331
4/4
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 73 times.
✓ Branch 2 taken 37 times.
✓ Branch 3 taken 36 times.
115 if (switchhook ? isSwitchHookable(cmb) : isHSGrabbable(cmb))
2332 {
2333 79 ffc = ffc_handle.ffc;
2334 79 return false;
2335 }
2336 36 }
2337 6889 return true;
2338 6896 });
2339 3393 }
2340
2341
4/4
✓ Branch 0 taken 61401 times.
✓ Branch 1 taken 64592 times.
✓ Branch 2 taken 442 times.
✓ Branch 3 taken 60959 times.
125993 if (out_rpos && cpos != rpos_t::None) *out_rpos = cpos;
2342
4/4
✓ Branch 0 taken 28389 times.
✓ Branch 1 taken 97604 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 28382 times.
125993 if (out_ffc && ffc) *out_ffc = ffc;
2343
2/2
✓ Branch 0 taken 65034 times.
✓ Branch 1 taken 60959 times.
125993 return (cpos != rpos_t::None || ffc);
2344 }
2345
2346 5195 bool ishookshottable(int32_t bx, int32_t by)
2347 {
2348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5195 times.
5195 if(!_walkflag(bx,by,1))
2349 return true;
2350
2351
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5187 times.
5195 if (collide_object(bx, by, 1, 1))
2352 8 return false;
2353
2354 5187 bool ret = true;
2355
2/2
✓ Branch 0 taken 15561 times.
✓ Branch 1 taken 1900 times.
17461 for(int32_t i=2; i>=0; i--)
2356 {
2357 15561 int32_t c = MAPCOMBO2(i-1,bx,by);
2358 15561 int32_t t = combobuf[c].type;
2359
2360
6/6
✓ Branch 0 taken 5187 times.
✓ Branch 1 taken 10374 times.
✓ Branch 2 taken 3853 times.
✓ Branch 3 taken 1334 times.
✓ Branch 4 taken 1900 times.
✓ Branch 5 taken 1953 times.
15561 if(i == 0 && (t == cHOOKSHOTONLY || t == cLADDERHOOKSHOT)) return true;
2361
2362
3/4
✓ Branch 0 taken 11321 times.
✓ Branch 1 taken 953 times.
✓ Branch 2 taken 953 times.
✗ Branch 3 not taken.
13227 bool dried = (iswater_type(t) && DRIEDLAKE);
2363
2364 12274 int32_t b=1;
2365
2366
2/2
✓ Branch 0 taken 6109 times.
✓ Branch 1 taken 6165 times.
12274 if(bx&8) b<<=2;
2367
2368
2/2
✓ Branch 0 taken 3841 times.
✓ Branch 1 taken 8433 times.
12274 if(by&8) b<<=1;
2369
2370
7/8
✓ Branch 0 taken 2094 times.
✓ Branch 1 taken 10180 times.
✓ Branch 2 taken 2094 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1115 times.
✓ Branch 5 taken 979 times.
✓ Branch 6 taken 75 times.
✓ Branch 7 taken 904 times.
12274 if(combobuf[c].walk&b && !dried && !(combo_class_buf[t].ladder_pass && t!=cLADDERONLY) && t!=cHOOKSHOTONLY)
2371 904 ret = false;
2372 12274 }
2373
2374 1900 return ret;
2375 5195 }
2376
2377 10102 bool reveal_hidden_stairs(mapscr *s, int32_t screen, bool redraw)
2378 {
2379
4/4
✓ Branch 0 taken 9524 times.
✓ Branch 1 taken 578 times.
✓ Branch 2 taken 9524 times.
✓ Branch 3 taken 578 times.
10102 if((s->stairx || s->stairy) && s->secretcombo[sSTAIRS])
2380 {
2381 578 int pos = COMBOPOS(s->stairx,s->stairy);
2382 578 s->data[pos] = s->secretcombo[sSTAIRS];
2383 578 s->cset[pos] = s->secretcset[sSTAIRS];
2384 578 s->sflag[pos] = s->secretflag[sSTAIRS];
2385
2386
2/2
✓ Branch 0 taken 255 times.
✓ Branch 1 taken 323 times.
578 if (redraw)
2387 {
2388 765 auto [x, y] = translate_screen_coordinates_to_world(screen, s->stairx, s->stairy);
2389 765 putcombo(scrollbuf,x,y,s->data[pos],s->cset[pos]);
2390 255 }
2391
2392 578 return true;
2393 }
2394
2395 9524 return false;
2396 10102 }
2397
2398 51669 screen_handles_t create_screen_handles_one(mapscr* base_scr)
2399 {
2400 DCHECK(base_scr->is_valid());
2401
2402 51669 screen_handles_t screen_handles{};
2403 51669 screen_handles[0] = {base_scr, base_scr, base_scr->screen, 0};
2404 51669 return screen_handles;
2405 }
2406
2407 56343232 screen_handles_t create_screen_handles(mapscr* base_scr)
2408 {
2409 DCHECK(get_scr(base_scr->screen) == base_scr);
2410 DCHECK(base_scr->is_valid());
2411
2412 56343232 int screen = base_scr->screen;
2413 screen_handles_t screen_handles;
2414 56343232 screen_handles[0] = {base_scr, base_scr, screen, 0};
2415
2/2
✓ Branch 0 taken 338059392 times.
✓ Branch 1 taken 56343232 times.
394402624 for (int i = 1; i <= 6; i++)
2416 338059392 screen_handles[i] = {base_scr, get_scr_layer_valid(screen, i), screen, i};
2417 56343232 return screen_handles;
2418 }
2419
2420 106202 bool remove_screenstatecombos2(const screen_handles_t& screen_handles, bool do_layers, int32_t what1, int32_t what2)
2421 {
2422 106202 mapscr* scr = screen_handles[0].scr;
2423 106202 bool didit=false;
2424
2425
2/2
✓ Branch 0 taken 106202 times.
✓ Branch 1 taken 18691552 times.
18797754 for(int32_t i=0; i<176; i++)
2426 {
2427 18691552 newcombo const& cmb = combobuf[scr->data[i]];
2428
2/2
✓ Branch 0 taken 326 times.
✓ Branch 1 taken 18691226 times.
18691552 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2429
4/4
✓ Branch 0 taken 18689693 times.
✓ Branch 1 taken 1533 times.
✓ Branch 2 taken 1102 times.
✓ Branch 3 taken 18688591 times.
18691226 if((cmb.type == what1) || (cmb.type== what2))
2430 {
2431 2635 scr->data[i]++;
2432 2635 didit=true;
2433 2635 }
2434 18691226 }
2435
2436
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 106110 times.
106202 if (do_layers)
2437 {
2438
2/2
✓ Branch 0 taken 636660 times.
✓ Branch 1 taken 106110 times.
742770 for(int32_t j=1; j<=6; j++)
2439 {
2440 636660 mapscr* layer_scr = screen_handles[j].scr;
2441
2/2
✓ Branch 0 taken 173044 times.
✓ Branch 1 taken 463616 times.
636660 if (!layer_scr) continue;
2442
2443
2/2
✓ Branch 0 taken 30455744 times.
✓ Branch 1 taken 173044 times.
30628788 for(int32_t i=0; i<176; i++)
2444 {
2445 30455744 newcombo const& cmb = combobuf[layer_scr->data[i]];
2446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30455744 times.
30455744 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2447
4/4
✓ Branch 0 taken 30455661 times.
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 265 times.
✓ Branch 3 taken 30455396 times.
30455744 if((cmb.type== what1) || (cmb.type== what2))
2448 {
2449 348 layer_scr->data[i]++;
2450 348 didit=true;
2451 348 }
2452 30455744 }
2453 173044 }
2454 106110 }
2455
2456 // 'do_layers' also means that this is called on an active temp screen, so update its ffcs.
2457
3/4
✓ Branch 0 taken 20406 times.
✓ Branch 1 taken 85796 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20406 times.
106202 if (!get_qr(qr_OLD_FFC_FUNCTIONALITY) && do_layers)
2458 {
2459 20406 word c = scr->numFFC();
2460
2/2
✓ Branch 0 taken 73350 times.
✓ Branch 1 taken 20406 times.
93756 for(word i=0; i<c; i++)
2461 {
2462 73350 ffcdata* ffc = &scr->ffcs[i];
2463 73350 newcombo const& cmb = combobuf[ffc->data];
2464
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73350 times.
73350 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2465
2/4
✓ Branch 0 taken 73350 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 73350 times.
73350 if((cmb.type== what1) || (cmb.type== what2))
2466 {
2467 zc_ffc_modify(*ffc, 1);
2468 didit=true;
2469 }
2470 73350 }
2471 20406 }
2472
2473 106202 return didit;
2474 }
2475
2476 14 bool remove_xstatecombos(const screen_handles_t& screen_handles, byte xflag, bool triggers)
2477 {
2478 14 int screen = screen_handles[0].scr->screen;
2479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2480 14 return remove_xstatecombos_mi(screen_handles, mi, xflag, triggers);
2481 }
2482 469722766 bool remove_xstatecombos_mi(const screen_handles_t& screen_handles, int32_t mi, byte xflag, bool triggers)
2483 {
2484 469722766 bool didit=false;
2485
2/2
✓ Branch 0 taken 469690671 times.
✓ Branch 1 taken 32095 times.
469722766 if(!getxmapflag_mi(mi, 1<<xflag)) return false;
2486
2487 32095 mapscr* s = screen_handles[0].scr;
2488 32095 int screen = s->screen;
2489 32095 bool is_active_screen = is_in_current_region(s);
2490
2491 26530479 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
2492
4/4
✓ Branch 0 taken 26486768 times.
✓ Branch 1 taken 11616 times.
✓ Branch 2 taken 26484974 times.
✓ Branch 3 taken 1794 times.
26498384 if(triggers && force_ex_trigger_any(rpos_handle, xflag))
2493 1794 didit = true;
2494
2/2
✓ Branch 0 taken 63627 times.
✓ Branch 1 taken 26432963 times.
26496590 else switch (rpos_handle.ctype())
2495 {
2496 case cLOCKBLOCK: case cLOCKBLOCK2:
2497 case cBOSSLOCKBLOCK: case cBOSSLOCKBLOCK2:
2498 case cCHEST: case cCHEST2:
2499 case cLOCKEDCHEST: case cLOCKEDCHEST2:
2500 case cBOSSCHEST: case cBOSSCHEST2:
2501 {
2502 63627 auto& cmb = rpos_handle.combo();
2503
2/2
✓ Branch 0 taken 62059 times.
✓ Branch 1 taken 1568 times.
63627 if(!(cmb.usrflags&cflag16)) return; //custom state instead of normal state
2504
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 62030 times.
62059 if(cmb.attribytes[5] == xflag)
2505 {
2506 29 rpos_handle.increment_data();
2507 29 didit=true;
2508 29 }
2509 62059 break;
2510 }
2511 }
2512 26498384 });
2513
2514
4/4
✓ Branch 0 taken 32054 times.
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 22434 times.
✓ Branch 3 taken 9620 times.
32095 if (is_active_screen && !get_qr(qr_OLD_FFC_FUNCTIONALITY))
2515 {
2516 22434 word c = s->numFFC();
2517 22434 int screen_index_offset = get_region_screen_offset(screen);
2518
2/2
✓ Branch 0 taken 36840 times.
✓ Branch 1 taken 22434 times.
59274 for (uint8_t i = 0; i < c; i++)
2519 {
2520 36840 auto ffc_handle = *s->getFFCHandle(i, screen_index_offset);
2521 36840 auto& cmb = ffc_handle.combo();
2522
3/4
✓ Branch 0 taken 36840 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36824 times.
✓ Branch 3 taken 16 times.
36840 if(triggers && force_ex_trigger_ffc_any(ffc_handle, xflag))
2523 16 didit = true;
2524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36824 times.
36824 else switch(cmb.type)
2525 {
2526 case cLOCKBLOCK: case cLOCKBLOCK2:
2527 case cBOSSLOCKBLOCK: case cBOSSLOCKBLOCK2:
2528 case cCHEST: case cCHEST2:
2529 case cLOCKEDCHEST: case cLOCKEDCHEST2:
2530 case cBOSSCHEST: case cBOSSCHEST2:
2531 {
2532 if(!(cmb.usrflags&cflag16)) continue; //custom state instead of normal state
2533 if(cmb.attribytes[5] == xflag)
2534 {
2535 zc_ffc_modify(*ffc_handle.ffc, 1);
2536 didit=true;
2537 }
2538 break;
2539 }
2540 }
2541 36840 }
2542 22434 }
2543
2544 32095 return didit;
2545 469722766 }
2546
2547 14626939 void clear_xstatecombos(const screen_handles_t& screen_handles, bool triggers)
2548 {
2549 14626939 int screen = screen_handles[0].screen;
2550
2/2
✓ Branch 0 taken 385099 times.
✓ Branch 1 taken 14241840 times.
14626939 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2551 14626939 clear_xstatecombos_mi(screen_handles, mi, triggers);
2552 14626939 }
2553
2554 14678836 void clear_xstatecombos_mi(const screen_handles_t& screen_handles, int32_t mi, bool triggers)
2555 {
2556
2/2
✓ Branch 0 taken 469722752 times.
✓ Branch 1 taken 14678836 times.
484401588 for (int q = 0; q < 32; ++q)
2557 {
2558 469722752 remove_xstatecombos_mi(screen_handles, mi, q, triggers);
2559 469722752 }
2560 14678836 }
2561
2562 bool remove_xdoors(const screen_handles_t& screen_handles, uint dir, uint ind, bool triggers)
2563 {
2564 int screen = screen_handles[0].screen;
2565 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2566 return remove_xdoors_mi(screen_handles, mi, dir, ind, triggers);
2567 }
2568 469722752 bool remove_xdoors_mi(const screen_handles_t& screen_handles, int32_t mi, uint dir, uint ind, bool triggers)
2569 {
2570 469722752 bool didit=false;
2571
2/2
✓ Branch 0 taken 469717928 times.
✓ Branch 1 taken 4824 times.
469722752 if (!getxdoor_mi(mi, dir, ind)) return false;
2572
2573 4824 mapscr* scr = screen_handles[0].scr;
2574 4824 int screen = scr->screen;
2575 4824 bool is_active_screen = is_in_current_region(scr);
2576
2577 3400920 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
2578
3/4
✓ Branch 0 taken 3396096 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 58 times.
✓ Branch 3 taken 3396038 times.
3396096 if (triggers && force_ex_door_trigger_any(rpos_handle, dir, ind))
2579 58 didit = true;
2580 else; //future door combo types?
2581 3396096 });
2582
2583
2/4
✓ Branch 0 taken 4824 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4824 times.
✗ Branch 3 not taken.
4824 if (!get_qr(qr_OLD_FFC_FUNCTIONALITY) && is_active_screen)
2584 {
2585 4824 word c = scr->numFFC();
2586 4824 int screen_index_offset = get_region_screen_offset(screen);
2587
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4824 times.
4824 for (uint8_t i = 0; i < c; i++)
2588 {
2589 auto ffc_handle = *scr->getFFCHandle(i, screen_index_offset);
2590 if (triggers && force_ex_door_trigger_ffc_any(ffc_handle, dir, ind))
2591 didit = true;
2592 else; //future door combo types?
2593 }
2594 4824 }
2595
2596 4824 return didit;
2597 469722752 }
2598
2599 14626939 void clear_xdoors(const screen_handles_t& screen_handles, bool triggers)
2600 {
2601 14626939 int screen = screen_handles[0].screen;
2602
2/2
✓ Branch 0 taken 385099 times.
✓ Branch 1 taken 14241840 times.
14626939 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2603 14626939 return clear_xdoors_mi(screen_handles, mi, triggers);
2604 }
2605
2606 14678836 void clear_xdoors_mi(const screen_handles_t& screen_handles, int32_t mi, bool triggers)
2607 {
2608
2/2
✓ Branch 0 taken 58715344 times.
✓ Branch 1 taken 14678836 times.
73394180 for (int dir = 0; dir < 4; ++dir)
2609
2/2
✓ Branch 0 taken 469722752 times.
✓ Branch 1 taken 58715344 times.
528438096 for (int q = 0; q < 8; ++q)
2610 528438096 remove_xdoors_mi(screen_handles, mi, dir, q, triggers);
2611 14678836 }
2612
2613 763 bool remove_lockblocks(const screen_handles_t& screen_handles)
2614 {
2615 763 return remove_screenstatecombos2(screen_handles, true, cLOCKBLOCK, cLOCKBLOCK2);
2616 }
2617
2618 98 bool remove_bosslockblocks(const screen_handles_t& screen_handles)
2619 {
2620 98 return remove_screenstatecombos2(screen_handles, true, cBOSSLOCKBLOCK, cBOSSLOCKBLOCK2);
2621 }
2622
2623 76553 bool remove_chests(const screen_handles_t& screen_handles)
2624 {
2625 76553 return remove_screenstatecombos2(screen_handles, true, cCHEST, cCHEST2);
2626 }
2627
2628 2484 bool remove_lockedchests(const screen_handles_t& screen_handles)
2629 {
2630 2484 return remove_screenstatecombos2(screen_handles, true, cLOCKEDCHEST, cLOCKEDCHEST2);
2631 }
2632
2633 26212 bool remove_bosschests(const screen_handles_t& screen_handles)
2634 {
2635 26212 return remove_screenstatecombos2(screen_handles, true, cBOSSCHEST, cBOSSCHEST2);
2636 }
2637
2638 1384283 void delete_fireball_shooter(const rpos_handle_t& rpos_handle)
2639 {
2640 1384283 int32_t ct=rpos_handle.ctype();
2641
2642
6/6
✓ Branch 0 taken 1383664 times.
✓ Branch 1 taken 619 times.
✓ Branch 2 taken 1383413 times.
✓ Branch 3 taken 251 times.
✓ Branch 4 taken 1383305 times.
✓ Branch 5 taken 108 times.
1384283 if(ct!=cL_STATUE && ct!=cR_STATUE && ct!=cC_STATUE)
2643 1383305 return;
2644
2645 2461 auto [cx, cy] = rpos_handle.xy();
2646
3/4
✓ Branch 0 taken 251 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 619 times.
✓ Branch 3 taken 108 times.
978 switch(ct)
2647 {
2648 case cL_STATUE:
2649 619 cx += 4;
2650 619 cy += 7;
2651 619 break;
2652
2653 case cR_STATUE:
2654 251 cx -= 8;
2655 251 cy -= 1;
2656 251 break;
2657
2658 case cC_STATUE:
2659 108 break;
2660 }
2661
2662
2/2
✓ Branch 0 taken 978 times.
✓ Branch 1 taken 1483 times.
2461 for(int32_t j=0; j<guys.Count(); j++)
2663 {
2664 // Finds the smallest enemy ID
2665
9/10
✓ Branch 0 taken 397 times.
✓ Branch 1 taken 1086 times.
✓ Branch 2 taken 397 times.
✓ Branch 3 taken 1086 times.
✓ Branch 4 taken 344 times.
✓ Branch 5 taken 53 times.
✓ Branch 6 taken 344 times.
✓ Branch 7 taken 53 times.
✓ Branch 8 taken 344 times.
✗ Branch 9 not taken.
2966 if((int32_t(guys.spr(j)->x)==cx)&&(int32_t(guys.spr(j)->y)==cy)&&(guysbuf[(guys.spr(j)->id)&0xFFF].flags & guy_fire))
2666 {
2667 344 guys.del(j);
2668 344 }
2669 1483 }
2670 1384283 }
2671
2672 15 static int32_t findtrigger(int32_t screen)
2673 {
2674 15 int32_t checkflag=0;
2675 15 int32_t ret = 0;
2676
2677 mapscr* screens[7];
2678
2/2
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 15 times.
120 for (int32_t j = 0; j <= 6; j++)
2679 {
2680 105 screens[j] = get_scr_layer_valid(screen, j);
2681 105 }
2682
2683 15 bool sflag = false;
2684
2/2
✓ Branch 0 taken 2640 times.
✓ Branch 1 taken 15 times.
2655 for(word j=0; j<176; j++)
2685 {
2686
2/2
✓ Branch 0 taken 26752 times.
✓ Branch 1 taken 2640 times.
29392 for(int32_t layer = -1; layer < 6; ++layer)
2687 {
2688 26752 mapscr* scr = screens[layer+1];
2689
2/2
✓ Branch 0 taken 16544 times.
✓ Branch 1 taken 10208 times.
26752 if (!scr) continue;
2690
2691
2/2
✓ Branch 0 taken 8272 times.
✓ Branch 1 taken 8272 times.
16544 if(sflag)
2692 8272 checkflag = scr->sflag[j];
2693 else
2694 8272 checkflag = combobuf[scr->data[j]].flag;
2695 16544 sflag = !sflag;
2696
2/2
✓ Branch 0 taken 8272 times.
✓ Branch 1 taken 8272 times.
16544 if (sflag) --layer;
2697
2698
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 16534 times.
16544 switch(checkflag)
2699 {
2700 case mfANYFIRE:
2701 case mfSTRONGFIRE:
2702 case mfMAGICFIRE:
2703 case mfDIVINEFIRE:
2704 case mfARROW:
2705 case mfSARROW:
2706 case mfGARROW:
2707 case mfSBOMB:
2708 case mfBOMB:
2709 case mfBRANG:
2710 case mfMBRANG:
2711 case mfFBRANG:
2712 case mfWANDMAGIC:
2713 case mfREFMAGIC:
2714 case mfREFFIREBALL:
2715 case mfSWORD:
2716 case mfWSWORD:
2717 case mfMSWORD:
2718 case mfXSWORD:
2719 case mfSWORDBEAM:
2720 case mfWSWORDBEAM:
2721 case mfMSWORDBEAM:
2722 case mfXSWORDBEAM:
2723 case mfHOOKSHOT:
2724 case mfWAND:
2725 case mfHAMMER:
2726 case mfSTRIKE:
2727 10 ret += 1;
2728 10 break;
2729 }
2730 16544 }
2731 2640 }
2732
2733 15 return ret;
2734 }
2735
2736 11709 static void log_trigger_secret_reason(TriggerSource source)
2737 {
2738
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11270 times.
11709 if (source == TriggerSource::Singular)
2739 {
2740 439 Z_eventlog("Restricted Screen Secrets triggered\n");
2741 439 }
2742 else
2743 {
2744 11270 const char* source_str = "";
2745
7/12
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 7169 times.
✓ Branch 3 taken 840 times.
✓ Branch 4 taken 2729 times.
✓ Branch 5 taken 475 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 52 times.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
11270 switch (source)
2746 {
2747 case TriggerSource::Singular: break;
2748 7169 case TriggerSource::Unspecified: source_str = "unspecified means"; break;
2749 840 case TriggerSource::EnemiesScreenFlag: source_str = "the 'Enemies->Secret' screen flag"; break;
2750 2729 case TriggerSource::SecretsScreenState: source_str = "the 'Secrets' screen state"; break;
2751 475 case TriggerSource::Script: source_str = "a script"; break;
2752 1 case TriggerSource::ItemsSecret: source_str = "Items->Secrets"; break;
2753 52 case TriggerSource::GenericCombo: source_str = "Generic Combo"; break;
2754 4 case TriggerSource::LightTrigger: source_str = "Light Triggers"; break;
2755 case TriggerSource::SCC: source_str = "SCC"; break;
2756 case TriggerSource::CheatTemp: source_str = "Cheat (Temp)"; break;
2757 case TriggerSource::CheatPerm: source_str = "Cheat (Perm)"; break;
2758 }
2759 11270 Z_eventlog("Screen Secrets triggered by %s\n", source_str);
2760 }
2761 11709 }
2762
2763 // single:
2764 // >-1 : the singular triggering combo
2765 // -1: triggered by some other cause
2766 11503 void trigger_secrets_for_screen(TriggerSource source, mapscr* scr, bool high16only, int32_t single)
2767 {
2768 11503 log_trigger_secret_reason(source);
2769
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11064 times.
11503 if (single < 0)
2770 11064 get_screen_state(scr->screen).triggered_secrets = true;
2771
2772 11503 bool do_replay_comment = true;
2773 11503 bool from_active_screen = true;
2774 11503 trigger_secrets_for_screen_internal(create_screen_handles(scr), from_active_screen, high16only, single, do_replay_comment);
2775
2776 // Respect secret state carryovers for active screens.
2777
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11064 times.
11503 if (single >= 0) return;
2778 11064 int flag = mSECRET;
2779 11064 int cmap = scr->map;
2780 11064 int cscr = scr->screen;
2781 11064 int nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
2782 11064 int nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
2783
2784 11064 std::vector<int32_t> done;
2785
2/2
✓ Branch 0 taken 10877 times.
✓ Branch 1 taken 187 times.
11064 bool looped = (nmap==cmap+1 && nscr==cscr);
2786
2787
6/6
✓ Branch 0 taken 629 times.
✓ Branch 1 taken 10987 times.
✓ Branch 2 taken 77 times.
✓ Branch 3 taken 552 times.
✓ Branch 4 taken 552 times.
✓ Branch 5 taken 11064 times.
11616 while((nmap!=0) && !looped && !(nscr>=128))
2788 {
2789
9/10
✓ Branch 0 taken 385 times.
✓ Branch 1 taken 167 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 301 times.
✓ Branch 4 taken 74 times.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 74 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 70 times.
552 if (nmap - 1 == cur_map && is_in_current_region(nscr) && (scr->nocarry&flag)!=flag && !get_screen_state(nscr).triggered_secrets)
2790 {
2791
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 log_trigger_secret_reason(TriggerSource::SecretsScreenState);
2792
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 trigger_secrets_for_screen_internal(create_screen_handles(get_scr(nscr)), from_active_screen, high16only, single, do_replay_comment);
2793
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 get_screen_state(nscr).triggered_secrets = true;
2794 4 }
2795
2796 552 cmap=nmap;
2797 552 cscr=nscr;
2798 552 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
2799 552 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
2800
2801
2/2
✓ Branch 0 taken 1101 times.
✓ Branch 1 taken 552 times.
1653 for(auto it = done.begin(); it != done.end(); it++)
2802 {
2803
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 77 times.
1101 if(*it == ((nmap-1)<<7)+nscr)
2804 77 looped = true;
2805 1101 }
2806
2807
1/2
✓ Branch 0 taken 552 times.
✗ Branch 1 not taken.
552 done.push_back(((nmap-1)<<7)+nscr);
2808 }
2809 11503 }
2810
2811 2432 void trigger_secrets_for_screen(TriggerSource source, int32_t screen, bool high16only, int32_t single)
2812 {
2813 2432 trigger_secrets_for_screen(source, get_scr(screen), high16only, single);
2814 2432 }
2815
2816 17978 void trigger_secrets_for_screen_internal(const screen_handles_t& screen_handles, bool from_active_screen, bool high16only, int32_t single, bool do_replay_comment)
2817 {
2818 17978 mapscr* scr = screen_handles[0].scr;
2819 17978 int screen = scr->screen;
2820
2821 // TODO(replays): No real reason for "do_replay_comment" to exist - I just did not want to update many replays when fixing
2822 // slopes in sideview mode (which required loading nearby screens in loadscr).
2823 // TODO(replays): This should just use `screen`.
2824
3/4
✓ Branch 0 taken 17978 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 539 times.
✓ Branch 3 taken 17439 times.
17978 if (replay_is_active() && do_replay_comment)
2825
4/6
✓ Branch 0 taken 11507 times.
✓ Branch 1 taken 5932 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11507 times.
✓ Branch 4 taken 17439 times.
✗ Branch 5 not taken.
17439 replay_step_comment(fmt::format("trigger secrets scr={}", from_active_screen && scr != special_warp_return_scr ? screen : cur_screen));
2826
2827
2/2
✓ Branch 0 taken 6471 times.
✓ Branch 1 taken 11507 times.
17978 if (from_active_screen)
2828 {
2829 5432763 for_every_combo_in_screen(screen_handles, [&](const auto& handle) {
2830 5421256 auto cid = handle.data();
2831 5421256 auto& cmb = handle.combo();
2832
4/4
✓ Branch 0 taken 5419523 times.
✓ Branch 1 taken 230393 times.
✓ Branch 2 taken 1688 times.
✓ Branch 3 taken 182 times.
5651786 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
2833 {
2834 230575 auto& trig = cmb.triggers[idx];
2835
3/4
✓ Branch 0 taken 66456 times.
✓ Branch 1 taken 163937 times.
✓ Branch 2 taken 182 times.
✗ Branch 3 not taken.
230575 if (trig.triggerflags[2] & combotriggerSECRETSTR)
2836 {
2837 163937 do_trigger_combo(handle, idx, ctrigSECRETS);
2838
2/4
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 163892 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
163937 if(handle.data() != cid) break;
2839 163892 }
2840 230530 }
2841 5421256 });
2842 11507 }
2843
2844 17978 int32_t ft=0; //Flag trigger?
2845 17978 int32_t msflag=0; // Misc. secret flag
2846
2847
2/2
✓ Branch 0 taken 3164128 times.
✓ Branch 1 taken 17978 times.
3182106 for(int32_t i=0; i<176; i++) //Do the 'trigger flags' (non 16-31)
2848 {
2849
4/4
✓ Branch 0 taken 77264 times.
✓ Branch 1 taken 3086864 times.
✓ Branch 2 taken 439 times.
✓ Branch 3 taken 76825 times.
3164128 if(single>=0 && i!=single) continue; //If it's got a singular flag and i isn't where the flag is
2850
2851 // Remember the misc. secret flag; if triggered, use this instead
2852
4/4
✓ Branch 0 taken 114433 times.
✓ Branch 1 taken 2972870 times.
✓ Branch 2 taken 49454 times.
✓ Branch 3 taken 64979 times.
3087303 if(scr->sflag[i]>=mfSECRETS01 && scr->sflag[i]<=mfSECRETS16)
2853 64979 msflag=sSECRET01+(scr->sflag[i]-mfSECRETS01);
2854
4/4
✓ Branch 0 taken 47230 times.
✓ Branch 1 taken 2975094 times.
✓ Branch 2 taken 46999 times.
✓ Branch 3 taken 231 times.
3022324 else if(combobuf[scr->data[i]].flag>=mfSECRETS01 && combobuf[scr->data[i]].flag<=mfSECRETS16)
2855 231 msflag=sSECRET01+(combobuf[scr->data[i]].flag-mfSECRETS01);
2856 else
2857 3022093 msflag=0;
2858
2859
4/4
✓ Branch 0 taken 917736 times.
✓ Branch 1 taken 2169567 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 917664 times.
3087303 if(!high16only || single>=0)
2860 {
2861 2169639 int32_t newflag = -1;
2862
2863
2/2
✓ Branch 0 taken 4339278 times.
✓ Branch 1 taken 2169639 times.
6508917 for(int32_t iter=0; iter<2; ++iter)
2864 {
2865 4339278 int32_t checkflag=combobuf[scr->data[i]].flag; //Inherent
2866
2867
2/2
✓ Branch 0 taken 2169639 times.
✓ Branch 1 taken 2169639 times.
4339278 if(iter==1) checkflag=scr->sflag[i]; //Placed
2868
2869 4339278 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
2870
2/2
✓ Branch 0 taken 4327054 times.
✓ Branch 1 taken 12224 times.
4339278 if (ft != -1) //Change the combos for the secret
2871 {
2872 // Use misc. secret flag instead if one is present
2873
2/2
✓ Branch 0 taken 12192 times.
✓ Branch 1 taken 32 times.
12224 if(msflag!=0)
2874 32 ft=msflag;
2875
2876 12224 rpos_handle_t rpos_handle;
2877
2/2
✓ Branch 0 taken 6365 times.
✓ Branch 1 taken 5859 times.
12224 if (from_active_screen)
2878 {
2879 5859 rpos_handle = get_rpos_handle_for_scr(scr, 0, i);
2880 5859 screen_combo_modify_preroutine(rpos_handle);
2881 5859 }
2882
2883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12224 times.
12224 if(ft==sSECNEXT)
2884 {
2885 scr->data[i]++;
2886 }
2887 else
2888 {
2889 12224 scr->data[i] = scr->secretcombo[ft];
2890 12224 scr->cset[i] = scr->secretcset[ft];
2891 }
2892 12224 newflag = scr->secretflag[ft];
2893
2894
2/2
✓ Branch 0 taken 6365 times.
✓ Branch 1 taken 5859 times.
12224 if (from_active_screen)
2895 5859 screen_combo_modify_postroutine(rpos_handle);
2896 12224 }
2897 4339278 }
2898
2899
2/2
✓ Branch 0 taken 2157421 times.
✓ Branch 1 taken 12218 times.
2169639 if(newflag >-1) scr->sflag[i] = newflag; //Tiered secret
2900
2901
2/2
✓ Branch 0 taken 13017834 times.
✓ Branch 1 taken 2169639 times.
15187473 for(int32_t j=1; j<=6; j++) //Layers
2902 {
2903 13017834 mapscr* layer_scr = screen_handles[j].scr;
2904
2/2
✓ Branch 0 taken 3182981 times.
✓ Branch 1 taken 9834853 times.
13017834 if (!layer_scr) continue;
2905
2906
3/4
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 3182256 times.
✓ Branch 2 taken 725 times.
✗ Branch 3 not taken.
3182981 if(single>=0 && i!=single) continue; //If it's got a singular flag and i isn't where the flag is
2907
2908 3182981 int32_t newflag2 = -1;
2909
2910 // Remember the misc. secret flag; if triggered, use this instead
2911
4/4
✓ Branch 0 taken 14169 times.
✓ Branch 1 taken 3168812 times.
✓ Branch 2 taken 4773 times.
✓ Branch 3 taken 9396 times.
3182981 if(layer_scr->sflag[i]>=mfSECRETS01 && layer_scr->sflag[i]<=mfSECRETS16)
2912 9396 msflag=sSECRET01+(layer_scr->sflag[i]-mfSECRETS01);
2913
4/4
✓ Branch 0 taken 126931 times.
✓ Branch 1 taken 3046654 times.
✓ Branch 2 taken 126560 times.
✓ Branch 3 taken 371 times.
3173585 else if(combobuf[layer_scr->data[i]].flag>=mfSECRETS01 && combobuf[layer_scr->data[i]].flag<=mfSECRETS16)
2914 371 msflag=sSECRET01+(combobuf[layer_scr->data[i]].flag-mfSECRETS01);
2915 else
2916 3173214 msflag=0;
2917
2918
2/2
✓ Branch 0 taken 6365962 times.
✓ Branch 1 taken 3182981 times.
9548943 for(int32_t iter=0; iter<2; ++iter)
2919 {
2920 6365962 int32_t checkflag=combobuf[layer_scr->data[i]].flag; //Inherent
2921
2/2
✓ Branch 0 taken 3182981 times.
✓ Branch 1 taken 3182981 times.
6365962 if(iter==1) checkflag=layer_scr->sflag[i]; //Placed
2922
2923 6365962 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
2924
2/2
✓ Branch 0 taken 6365484 times.
✓ Branch 1 taken 478 times.
6365962 if (ft != -1) //Change the combos for the secret
2925 {
2926 // Use misc. secret flag instead if one is present
2927
2/2
✓ Branch 0 taken 476 times.
✓ Branch 1 taken 2 times.
478 if(msflag!=0)
2928 2 ft=msflag;
2929
2930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 478 times.
478 if(ft==sSECNEXT)
2931 {
2932 layer_scr->data[i]++;
2933 }
2934 else
2935 {
2936 478 layer_scr->data[i] = layer_scr->secretcombo[ft];
2937 478 layer_scr->cset[i] = layer_scr->secretcset[ft];
2938 }
2939 478 newflag2 = layer_scr->secretflag[ft];
2940 478 int32_t c=layer_scr->data[i];
2941 478 int32_t cs=layer_scr->cset[i];
2942
2943
3/4
✓ Branch 0 taken 406 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 406 times.
✗ Branch 3 not taken.
478 if (from_active_screen && combobuf[c].type==cSPINTILE1) //Surely this means we can have spin tiles on layers 3+? Isn't that bad? ~Joe123
2944 {
2945 auto [offx, offy] = translate_screen_coordinates_to_world(screen, COMBOX(i), COMBOY(i));
2946 addenemy(screen,offx,offy,(cs<<12)+eSPINTILE1,combobuf[c].o_tile+zc_max(1,combobuf[c].frames));
2947 }
2948 478 }
2949 6365962 }
2950
2951
2/2
✓ Branch 0 taken 478 times.
✓ Branch 1 taken 3182503 times.
3182981 if(newflag2 >-1) layer_scr->sflag[i] = newflag2; //Tiered secret
2952 3182981 }
2953 2169639 }
2954 3087303 }
2955
2956 17978 word c = scr->numFFC();
2957
2/2
✓ Branch 0 taken 505943 times.
✓ Branch 1 taken 17978 times.
523921 for(word i=0; i<c; i++) //FFC 'trigger flags'
2958 {
2959
3/4
✓ Branch 0 taken 492023 times.
✓ Branch 1 taken 13920 times.
✓ Branch 2 taken 13920 times.
✗ Branch 3 not taken.
505943 if(single>=0) if(i+176!=single) continue;
2960
2961
3/4
✓ Branch 0 taken 165965 times.
✓ Branch 1 taken 326058 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 165965 times.
492023 if((!high16only)||(single>=0))
2962 {
2963 //for (int32_t iter=0; iter<1; ++iter) // Only one kind of FFC flag now.
2964 {
2965 326058 int32_t checkflag=combobuf[scr->ffcs[i].data].flag; //Inherent
2966 //No placed flags yet
2967
2968 326058 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
2969
2/2
✓ Branch 0 taken 326027 times.
✓ Branch 1 taken 31 times.
326058 if (ft != -1) //Change the ffc's combo
2970 {
2971
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if(ft==sSECNEXT)
2972 {
2973 zc_ffc_modify(scr->ffcs[i], 1);
2974 }
2975 else
2976 {
2977 31 zc_ffc_set(scr->ffcs[i], scr->secretcombo[ft]);
2978 31 scr->ffcs[i].cset = scr->secretcset[ft];
2979 }
2980 31 }
2981 }
2982 326058 }
2983 492023 }
2984
2985
2/2
✓ Branch 0 taken 15586 times.
✓ Branch 1 taken 2392 times.
17978 if(checktrigger) //Hit all triggers->16-31
2986 {
2987 2392 checktrigger=false;
2988
2989
2/2
✓ Branch 0 taken 2383 times.
✓ Branch 1 taken 9 times.
2392 if(scr->flags6&fTRIGGERF1631)
2990 {
2991 9 int32_t tr = findtrigger(screen); //Normal flags
2992
2993
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
9 if(tr)
2994 {
2995 5 Z_eventlog("Hit All Triggers->16-31 not fulfilled (%d trigger flag%s remain).\n", tr, tr>1?"s":"");
2996 5 goto endhe;
2997 }
2998 4 }
2999 2387 }
3000
3001
2/2
✓ Branch 0 taken 3163248 times.
✓ Branch 1 taken 17973 times.
3181221 for(int32_t i=0; i<176; i++) // Do the 16-31 secrets
3002 {
3003 //If it's an enemies->secret screen, only do the high 16 if told to
3004 //That way you can have secret and burn/bomb entrance separately
3005 3163248 bool old_enem_secret = get_qr(qr_ENEMIES_SECRET_ONLY_16_31);
3006
6/6
✓ Branch 0 taken 2775344 times.
✓ Branch 1 taken 387904 times.
✓ Branch 2 taken 85184 times.
✓ Branch 3 taken 3078064 times.
✓ Branch 4 taken 19536 times.
✓ Branch 5 taken 65648 times.
3163248 if(((!(old_enem_secret && (scr->flags2&fCLEARSECRET)) /*Enemies->Secret*/ && single < 0) || high16only || scr->flags4&fENEMYSCRTPERM))
3007 {
3008 3097600 int32_t newflag = -1;
3009
3010
2/2
✓ Branch 0 taken 6195200 times.
✓ Branch 1 taken 3097600 times.
9292800 for(int32_t iter=0; iter<2; ++iter)
3011 {
3012 6195200 int32_t checkflag=combobuf[scr->data[i]].flag; //Inherent
3013
3014
2/2
✓ Branch 0 taken 3097600 times.
✓ Branch 1 taken 3097600 times.
6195200 if(iter==1) checkflag=scr->sflag[i]; //Placed
3015
3016
4/4
✓ Branch 0 taken 161110 times.
✓ Branch 1 taken 6034090 times.
✓ Branch 2 taken 94848 times.
✓ Branch 3 taken 66262 times.
6195200 if((checkflag > 15)&&(checkflag < 32)) //If we've got a 16->32 flag change the combo
3017 {
3018 66262 rpos_handle_t rpos_handle;
3019
2/2
✓ Branch 0 taken 9952 times.
✓ Branch 1 taken 56310 times.
66262 if (from_active_screen)
3020 {
3021 56310 rpos_handle = get_rpos_handle_for_scr(scr, 0, i);
3022 56310 screen_combo_modify_preroutine(rpos_handle);
3023 56310 }
3024
3025 66262 scr->data[i] = scr->secretcombo[checkflag-16+4];
3026 66262 scr->cset[i] = scr->secretcset[checkflag-16+4];
3027 66262 newflag = scr->secretflag[checkflag-16+4];
3028
3029
2/2
✓ Branch 0 taken 9952 times.
✓ Branch 1 taken 56310 times.
66262 if (from_active_screen)
3030 56310 screen_combo_modify_postroutine(rpos_handle);
3031 66262 }
3032 6195200 }
3033
3034
2/2
✓ Branch 0 taken 3031362 times.
✓ Branch 1 taken 66238 times.
3097600 if(newflag >-1) scr->sflag[i] = newflag; //Tiered flag
3035
3036
2/2
✓ Branch 0 taken 18585600 times.
✓ Branch 1 taken 3097600 times.
21683200 for(int32_t j=1; j<=6; j++) //Layers
3037 {
3038 18585600 mapscr* layer_scr = screen_handles[j].scr;
3039
2/2
✓ Branch 0 taken 4860592 times.
✓ Branch 1 taken 13725008 times.
18585600 if (!layer_scr) continue;
3040
3041 4860592 int32_t newflag2 = -1;
3042
3043
2/2
✓ Branch 0 taken 9721184 times.
✓ Branch 1 taken 4860592 times.
14581776 for(int32_t iter=0; iter<2; ++iter)
3044 {
3045 9721184 int32_t checkflag=combobuf[layer_scr->data[i]].flag; //Inherent
3046
3047
2/2
✓ Branch 0 taken 4860592 times.
✓ Branch 1 taken 4860592 times.
9721184 if(iter==1) checkflag=layer_scr->sflag[i]; //Placed
3048
3049
4/4
✓ Branch 0 taken 151199 times.
✓ Branch 1 taken 9569985 times.
✓ Branch 2 taken 131622 times.
✓ Branch 3 taken 19577 times.
9721184 if((checkflag > 15)&&(checkflag < 32)) //If we've got a 16->32 flag change the combo
3050 {
3051 19577 layer_scr->data[i] = layer_scr->secretcombo[checkflag-16+4];
3052 19577 layer_scr->cset[i] = layer_scr->secretcset[checkflag-16+4];
3053 19577 newflag2 = layer_scr->secretflag[checkflag-16+4];
3054 19577 }
3055 9721184 }
3056
3057
2/2
✓ Branch 0 taken 4841015 times.
✓ Branch 1 taken 19577 times.
4860592 if(newflag2 >-1) layer_scr->sflag[i] = newflag2; //Tiered flag
3058 4860592 }
3059 3097600 }
3060 3163248 }
3061
3062
2/2
✓ Branch 0 taken 505783 times.
✓ Branch 1 taken 17973 times.
523756 for(word i=0; i<c; i++) // FFCs
3063 {
3064
6/6
✓ Branch 0 taken 466436 times.
✓ Branch 1 taken 39347 times.
✓ Branch 2 taken 15367 times.
✓ Branch 3 taken 490416 times.
✓ Branch 4 taken 3530 times.
✓ Branch 5 taken 11837 times.
505783 if((!(scr->flags2&fCLEARSECRET) /*Enemies->Secret*/ && single < 0) || high16only || scr->flags4&fENEMYSCRTPERM)
3065 {
3066 493946 int32_t checkflag=combobuf[scr->ffcs[i].data].flag; //Inherent
3067
3068 //No placed flags yet
3069
4/4
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 493878 times.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 12 times.
493946 if((checkflag > 15)&&(checkflag < 32)) //If we find a flag, change the combo
3070 {
3071
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 if (from_active_screen)
3072 9 zc_ffc_set(scr->ffcs[i], scr->secretcombo[checkflag - 16 + 4]);
3073 else
3074 3 scr->ffcs[i].data = scr->secretcombo[checkflag - 16 + 4];
3075 12 scr->ffcs[i].cset = scr->secretcset[checkflag-16+4];
3076 12 }
3077 493946 }
3078 523756 }
3079
3080 endhe:
3081
3082
1/2
✓ Branch 0 taken 17978 times.
✗ Branch 1 not taken.
17978 if (scr->flags4&fDISABLETIME) //Finish timed warp if 'Secrets Disable Timed Warp'
3083 {
3084 if (from_active_screen)
3085 activated_timed_warp = true;
3086 scr->timedwarptics = 0;
3087 }
3088 17978 }
3089
3090 // x,y are world coordinates.
3091 // Returns true if there is a flag (either combo, screen, or ffc) at (x, y).
3092 // Out parameters will be set if the flag is Trigger->Self, which modifies how secrets will be triggered.
3093 13416501 static bool has_flag_trigger(int32_t x, int32_t y, int32_t flag, rpos_t& out_rpos, bool& out_single16)
3094 {
3095
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13416501 times.
13416501 if (!is_in_world_bounds(x, y)) return false;
3096
3097 13416501 bool found_cflag = false;
3098 13416501 bool found_nflag = false;
3099 13416501 bool single16 = false;
3100 13416501 rpos_t rpos = rpos_t::None;
3101
3102
2/2
✓ Branch 0 taken 13414422 times.
✓ Branch 1 taken 93903345 times.
107317767 for (int32_t layer = -1; layer < 6; layer++)
3103 {
3104
2/2
✓ Branch 0 taken 93901266 times.
✓ Branch 1 taken 2079 times.
93903345 if (MAPFLAG2(layer, x, y) == flag)
3105 {
3106 2079 found_nflag = true;
3107 2079 break;
3108 }
3109 93901266 }
3110
3111
2/2
✓ Branch 0 taken 13416197 times.
✓ Branch 1 taken 93914231 times.
107330428 for (int32_t layer = -1; layer < 6; layer++)
3112 {
3113
2/2
✓ Branch 0 taken 93913927 times.
✓ Branch 1 taken 304 times.
93914231 if (MAPCOMBOFLAG2(layer, x, y) == flag)
3114 {
3115 304 found_cflag = true;
3116 304 break;
3117 }
3118 93913927 }
3119
3120
2/2
✓ Branch 0 taken 93915507 times.
✓ Branch 1 taken 13416501 times.
107332008 for (int32_t i=-1; i<6; i++) // Look for Trigger->Self on all layers
3121 {
3122
2/2
✓ Branch 0 taken 93900954 times.
✓ Branch 1 taken 14553 times.
93915507 if (found_nflag) // Trigger->Self (a.k.a Singular) is inherent
3123 {
3124
3/4
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 14441 times.
✓ Branch 2 taken 112 times.
✗ Branch 3 not taken.
14553 if ((MAPCOMBOFLAG2(i, x, y) == mfSINGLE) && (MAPFLAG2(i, x, y) == flag))
3125 {
3126 112 rpos = COMBOPOS_REGION(x, y);
3127 112 }
3128
3/4
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 14389 times.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
14441 else if ((MAPCOMBOFLAG2(i, x, y) == mfSINGLE16) && (MAPFLAG2(i, x, y) == flag))
3129 {
3130 52 rpos = COMBOPOS_REGION(x, y);
3131 52 single16 = true;
3132 52 }
3133 14553 }
3134
3135
2/2
✓ Branch 0 taken 93913379 times.
✓ Branch 1 taken 2128 times.
93915507 if (found_cflag) // Trigger->Self (a.k.a Singular) is non-inherent
3136 {
3137
3/4
✓ Branch 0 taken 255 times.
✓ Branch 1 taken 1873 times.
✓ Branch 2 taken 255 times.
✗ Branch 3 not taken.
2128 if ((MAPFLAG2(i, x, y) == mfSINGLE) && (MAPCOMBOFLAG2(i, x, y) == flag))
3138 {
3139 255 rpos = COMBOPOS_REGION(x, y);
3140 255 }
3141
3/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1853 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
1873 else if ((MAPFLAG2(i, x, y) == mfSINGLE16) && (MAPCOMBOFLAG2(i, x, y) == flag))
3142 {
3143 20 rpos = COMBOPOS_REGION(x, y);
3144 20 single16 = true;
3145 20 }
3146 2128 }
3147 93915507 }
3148
3149 13416501 out_rpos = rpos;
3150 13416501 out_single16 = single16;
3151
4/4
✓ Branch 0 taken 13414422 times.
✓ Branch 1 taken 2079 times.
✓ Branch 2 taken 13414120 times.
✓ Branch 3 taken 302 times.
13416501 return found_nflag || found_cflag || MAPFFCOMBOFLAG(x,y) == flag;
3152 13416501 }
3153
3154 4426094 bool trigger_secrets_if_flag(int32_t x, int32_t y, int32_t flag, bool setflag)
3155 {
3156
8/8
✓ Branch 0 taken 4425854 times.
✓ Branch 1 taken 240 times.
✓ Branch 2 taken 4423957 times.
✓ Branch 3 taken 1897 times.
✓ Branch 4 taken 4423437 times.
✓ Branch 5 taken 520 times.
✓ Branch 6 taken 952 times.
✓ Branch 7 taken 4422485 times.
4426094 if (x < -16 || y < -16 || x >= world_w || y >= world_h) return false;
3157
3158 4422485 mapscr* scr = NULL;
3159 4422485 int32_t screen = -1;
3160 4422485 rpos_t trigger_rpos = rpos_t::None;
3161 4422485 bool single16 = false;
3162
3163 4422485 std::vector<std::pair<int, int>> coords;
3164
1/2
✓ Branch 0 taken 4422485 times.
✗ Branch 1 not taken.
4422485 coords.push_back({x, y});
3165
1/2
✓ Branch 0 taken 4422485 times.
✗ Branch 1 not taken.
4422485 coords.push_back({x + 15, y});
3166
1/2
✓ Branch 0 taken 4422485 times.
✗ Branch 1 not taken.
4422485 coords.push_back({x, y + 15});
3167
1/2
✓ Branch 0 taken 4422485 times.
✗ Branch 1 not taken.
4422485 coords.push_back({x + 15, y + 15});
3168 4422485 std::vector<rpos_t> rposes_seen;
3169
2/2
✓ Branch 0 taken 4420093 times.
✓ Branch 1 taken 17684665 times.
83888612 for (auto [x, y] : coords)
3170 {
3171
2/4
✓ Branch 0 taken 17684665 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17684665 times.
✗ Branch 3 not taken.
35369330 rpos_t rpos = COMBOPOS_REGION_B(x, y);
3172
2/2
✓ Branch 0 taken 17473034 times.
✓ Branch 1 taken 211631 times.
17684665 if (rpos == rpos_t::None)
3173 211631 continue;
3174
3175
4/6
✓ Branch 0 taken 17473034 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17473034 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 17473023 times.
34946068 if (MAPFFCOMBOFLAG(x, y) == flag)
3176 {
3177
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
22 screen = get_screen_for_world_xy(x, y);
3178 11 break;
3179 }
3180
3181 17473023 bool seen = false;
3182
2/2
✓ Branch 0 taken 13416501 times.
✓ Branch 1 taken 21973910 times.
35390411 for (rpos_t r : rposes_seen)
3183 {
3184
2/2
✓ Branch 0 taken 17917388 times.
✓ Branch 1 taken 4056522 times.
21973910 if (r == rpos)
3185 {
3186 4056522 seen = true;
3187 4056522 break;
3188 }
3189 }
3190
2/2
✓ Branch 0 taken 13416501 times.
✓ Branch 1 taken 4056522 times.
17473023 if (seen)
3191 4056522 continue;
3192
3193
1/2
✓ Branch 0 taken 13416501 times.
✗ Branch 1 not taken.
13416501 rposes_seen.push_back(rpos);
3194
4/6
✓ Branch 0 taken 13416501 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13416501 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2381 times.
✓ Branch 5 taken 13414120 times.
26833002 if (has_flag_trigger(x, y, flag, trigger_rpos, single16))
3195 {
3196
2/4
✓ Branch 0 taken 2381 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2381 times.
✗ Branch 3 not taken.
4762 screen = get_screen_for_world_xy(x, y);
3197 2381 break;
3198 }
3199 }
3200
3201
3/4
✓ Branch 0 taken 2392 times.
✓ Branch 1 taken 4420093 times.
✓ Branch 2 taken 2392 times.
✗ Branch 3 not taken.
4422485 if (screen != -1) scr = get_scr(screen);
3202
2/2
✓ Branch 0 taken 2392 times.
✓ Branch 1 taken 4420093 times.
4422485 if (!scr) return false;
3203
3204
2/2
✓ Branch 0 taken 1953 times.
✓ Branch 1 taken 439 times.
2392 if (trigger_rpos == rpos_t::None)
3205 {
3206 1953 checktrigger = true;
3207
1/2
✓ Branch 0 taken 1953 times.
✗ Branch 1 not taken.
1953 trigger_secrets_for_screen(TriggerSource::Unspecified, screen);
3208 1953 }
3209 else
3210 {
3211 439 checktrigger = true;
3212
2/4
✓ Branch 0 taken 439 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 439 times.
✗ Branch 3 not taken.
439 trigger_secrets_for_screen(TriggerSource::Singular, scr, single16, RPOS_TO_POS(trigger_rpos));
3213 }
3214
3215
1/2
✓ Branch 0 taken 2392 times.
✗ Branch 1 not taken.
2392 sfx(scr->secretsfx);
3216
3217
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2386 times.
2392 if(scr->flags6&fTRIGGERFPERM)
3218 {
3219
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 int32_t flags_remaining = findtrigger(screen); //Normal flags
3220
3221
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (flags_remaining)
3222 {
3223
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Z_eventlog("Hit All Triggers->Perm Secret not fulfilled (%d trigger flag%s remain).\n", flags_remaining, flags_remaining>1?"s":"");
3224 3 setflag=false;
3225 3 }
3226
3227 // Only actually trigger secrets now if 1) all triggers are gone and 2) QR qr_ALLTRIG_PERMSEC_NO_TEMP is off, in
3228 // which case only the screen state for mSECRET may be set below.
3229
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if (!flags_remaining && !get_qr(qr_ALLTRIG_PERMSEC_NO_TEMP))
3230 {
3231 trigger_secrets_for_screen(TriggerSource::Unspecified, scr, scr->flags6&fTRIGGERF1631, -1);
3232 }
3233 6 }
3234
3235
5/6
✓ Branch 0 taken 2287 times.
✓ Branch 1 taken 105 times.
✓ Branch 2 taken 2287 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1105 times.
✓ Branch 5 taken 1182 times.
2392 if (setflag && canPermSecret(cur_dmap, screen))
3236
2/2
✓ Branch 0 taken 719 times.
✓ Branch 1 taken 463 times.
1901 if(!(scr->flags5&fTEMPSECRETS))
3237
1/2
✓ Branch 0 taken 719 times.
✗ Branch 1 not taken.
719 setmapflag(scr, mSECRET);
3238
3239 2392 return true;
3240 4426094 }
3241
3242 14753885 void update_slopes()
3243 {
3244
2/2
✓ Branch 0 taken 142356 times.
✓ Branch 1 taken 14753885 times.
14896241 for (auto& p : slopes)
3245 {
3246 142356 slope_object& s = p.second;
3247 142356 s.updateslope(); //sets old x/y poses
3248 }
3249 14753885 }
3250
3251 14347046 void update_freeform_combos()
3252 {
3253 14347046 ffscript_engine(false);
3254
2/2
✓ Branch 0 taken 24172 times.
✓ Branch 1 taken 14322874 times.
14347046 if ( !FFCore.system_suspend[susptUPDATEFFC] )
3255 {
3256 14322874 int wrap_right = world_w + 32;
3257 14322874 int wrap_bottom = world_h + 32;
3258
3259 483537196 for_every_ffc([&](const ffc_handle_t& ffc_handle) {
3260 469214322 mapscr* scr = ffc_handle.scr;
3261 469214322 ffcdata& thisffc = *ffc_handle.ffc;
3262
3263 // Combo 0?
3264
2/2
✓ Branch 0 taken 44992137 times.
✓ Branch 1 taken 424222185 times.
469214322 if(thisffc.data==0)
3265 424222185 return;
3266
3267 // Changer?
3268
2/2
✓ Branch 0 taken 543029 times.
✓ Branch 1 taken 44449108 times.
44992137 if(thisffc.flags&ffc_changer)
3269 543029 return;
3270
3271 // Stationary?
3272
2/2
✓ Branch 0 taken 9844 times.
✓ Branch 1 taken 44439264 times.
44449108 if(thisffc.flags&ffc_stationary)
3273 9844 return;
3274
3275 // Frozen because Hero's holding up an item?
3276
3/4
✓ Branch 0 taken 138282 times.
✓ Branch 1 taken 44300982 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138282 times.
44439264 if(Hero.getHoldClk()>0 && (thisffc.flags&ffc_ignoreholdup)==0)
3277 138282 return;
3278
3279 // Check for changers
3280
2/2
✓ Branch 0 taken 29543718 times.
✓ Branch 1 taken 14757264 times.
44300982 if (thisffc.link==0)
3281 {
3282 442453057 for_some_ffcs([&](const ffc_handle_t& other_ffc_handle) {
3283
2/2
✓ Branch 0 taken 14755728 times.
✓ Branch 1 taken 412940065 times.
427695793 if (ffc_handle.id == other_ffc_handle.id)
3284 14755728 return true;
3285
3286 412940065 ffcdata& otherffc = *other_ffc_handle.ffc;
3287 // Combo 0?
3288
2/2
✓ Branch 0 taken 144689563 times.
✓ Branch 1 taken 268250502 times.
412940065 if(otherffc.data==0)
3289 268250502 return true;
3290
3291 // Not a changer?
3292
2/2
✓ Branch 0 taken 140701386 times.
✓ Branch 1 taken 3988177 times.
144689563 if(!(otherffc.flags&ffc_changer))
3293 140701386 return true;
3294
3295 // Ignore this changer?
3296
4/4
✓ Branch 0 taken 546579 times.
✓ Branch 1 taken 3441598 times.
✓ Branch 2 taken 299257 times.
✓ Branch 3 taken 3142341 times.
3988177 if((otherffc.x.getInt()==thisffc.changer_x&&otherffc.y.getInt()==thisffc.changer_y) || thisffc.flags&ffc_ignorechanger)
3297 845836 return true;
3298
3299
3/4
✓ Branch 0 taken 2721043 times.
✓ Branch 1 taken 421298 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3562 times.
3145903 if((isonline(thisffc.x.getZLong(), thisffc.y.getZLong(), thisffc.prev_changer_x, thisffc.prev_changer_y, otherffc.x.getZLong(), otherffc.y.getZLong()) || // Along the line, or...
3300 ( // At exactly the same position,
3301
2/2
✓ Branch 0 taken 208792 times.
✓ Branch 1 taken 2512251 times.
2721043 (thisffc.x==otherffc.x && thisffc.y==otherffc.y))
3302
2/2
✓ Branch 0 taken 2303459 times.
✓ Branch 1 taken 2512251 times.
208792 ||
3303 //or imprecision and close enough
3304
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
5024502 ( (thisffc.flags&ffc_imprecisionchanger) && ((abs(thisffc.x.getZLong() - otherffc.x.getZLong()) < 10000) && abs(thisffc.y.getZLong() - otherffc.y.getZLong()) < 10000) )
3305 )
3306 && //and...
3307
2/2
✓ Branch 0 taken 3562 times.
✓ Branch 1 taken 2721195 times.
2724757 (thisffc.prev_changer_x>-10000000 && thisffc.prev_changer_y>-10000000)) // This isn't the first frame on this screen
3308 {
3309 3562 zc_ffc_changer(thisffc, otherffc, ffc_handle.id, other_ffc_handle.id);
3310 3562 return false;
3311 }
3312
3313 2721195 return true;
3314 426679695 });
3315 14757264 }
3316
3317
2/2
✓ Branch 0 taken 29543718 times.
✓ Branch 1 taken 14757264 times.
44300982 ffcdata* linked_ffc = thisffc.link ? get_ffc_handle(thisffc.link - 1).ffc : nullptr;
3318
4/4
✓ Branch 0 taken 14757264 times.
✓ Branch 1 taken 29543718 times.
✓ Branch 2 taken 14679974 times.
✓ Branch 3 taken 14863744 times.
44300982 if (linked_ffc ? !linked_ffc->delay : !thisffc.delay)
3319 {
3320
4/4
✓ Branch 0 taken 182609 times.
✓ Branch 1 taken 14681135 times.
✓ Branch 2 taken 85331 times.
✓ Branch 3 taken 97278 times.
14863744 if(thisffc.link && (thisffc.link-1) != ffc_handle.id)
3321 {
3322 97278 thisffc.prev_changer_x = thisffc.x.getZLong();
3323 97278 thisffc.prev_changer_y = thisffc.y.getZLong();
3324 97278 thisffc.x += linked_ffc->vx;
3325 97278 thisffc.y += linked_ffc->vy;
3326 97278 }
3327 else
3328 {
3329 14766466 thisffc.prev_changer_x = thisffc.x.getZLong();
3330 14766466 thisffc.prev_changer_y = thisffc.y.getZLong();
3331 14766466 thisffc.x += thisffc.vx;
3332 14766466 thisffc.y += thisffc.vy;
3333 14766466 thisffc.vx += thisffc.ax;
3334 14766466 thisffc.vy += thisffc.ay;
3335
3336
3337
2/2
✓ Branch 0 taken 444012 times.
✓ Branch 1 taken 14322454 times.
14766466 if(get_qr(qr_OLD_FFC_SPEED_CAP))
3338 {
3339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vx>128) thisffc.vx=128;
3340
3341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vx<-128) thisffc.vx=-128;
3342
3343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vy>128) thisffc.vy=128;
3344
3345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vy<-128) thisffc.vy=-128;
3346 14322454 }
3347 }
3348 14863744 }
3349 else
3350 {
3351
3/4
✓ Branch 0 taken 1161 times.
✓ Branch 1 taken 76129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1161 times.
29437238 if(!thisffc.link || (thisffc.link-1) == ffc_handle.id)
3352 76129 thisffc.delay--;
3353 }
3354
3355 // Check if the FFC's off the side of the screen
3356
3357 // Left
3358
2/2
✓ Branch 0 taken 10449 times.
✓ Branch 1 taken 14930585 times.
14941034 if(thisffc.x<-32)
3359 {
3360
2/2
✓ Branch 0 taken 253 times.
✓ Branch 1 taken 10196 times.
10449 if(scr->flags6&fWRAPAROUNDFF)
3361 {
3362 253 thisffc.x = wrap_right+(thisffc.x+32);
3363 253 thisffc.solid_update(false);
3364 253 thisffc.prev_changer_y = thisffc.y.getZLong();
3365 // Re-enable previous changer
3366 253 thisffc.changer_x = -1000;
3367 253 thisffc.changer_y = -1000;
3368 253 }
3369
2/2
✓ Branch 0 taken 10127 times.
✓ Branch 1 taken 69 times.
10196 else if(thisffc.x<-64)
3370 {
3371 69 zc_ffc_set(thisffc, 0);
3372 69 thisffc.flags&=~ffc_carryover;
3373 69 }
3374 10449 }
3375 // Right
3376
2/2
✓ Branch 0 taken 14930404 times.
✓ Branch 1 taken 181 times.
14930585 else if(thisffc.x>=wrap_right)
3377 {
3378
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 53 times.
181 if(scr->flags6&fWRAPAROUNDFF)
3379 {
3380 128 thisffc.x = thisffc.x-wrap_right-32;
3381 128 thisffc.solid_update(false);
3382 128 thisffc.prev_changer_y = thisffc.y.getZLong();
3383 128 thisffc.changer_x = -1000;
3384 128 thisffc.changer_y = -1000;
3385 128 }
3386 else
3387 {
3388 53 zc_ffc_set(thisffc, 0);
3389 53 thisffc.flags&=~ffc_carryover;
3390 }
3391 181 }
3392
3393 // Top
3394
2/2
✓ Branch 0 taken 25480 times.
✓ Branch 1 taken 14915554 times.
14941034 if(thisffc.y<-32)
3395 {
3396
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 25472 times.
25480 if(scr->flags6&fWRAPAROUNDFF)
3397 {
3398 8 thisffc.y = wrap_bottom+(thisffc.y+32);
3399 8 thisffc.solid_update(false);
3400 8 thisffc.prev_changer_x = thisffc.x.getZLong();
3401 8 thisffc.changer_x = -1000;
3402 8 thisffc.changer_y = -1000;
3403 8 }
3404
2/2
✓ Branch 0 taken 25155 times.
✓ Branch 1 taken 317 times.
25472 else if(thisffc.y<-64)
3405 {
3406 317 zc_ffc_set(thisffc, 0);
3407 317 thisffc.flags&=~ffc_carryover;
3408 317 }
3409 25480 }
3410 // Bottom
3411
2/2
✓ Branch 0 taken 14914710 times.
✓ Branch 1 taken 844 times.
14915554 else if(thisffc.y>=wrap_bottom)
3412 {
3413
2/2
✓ Branch 0 taken 753 times.
✓ Branch 1 taken 91 times.
844 if(scr->flags6&fWRAPAROUNDFF)
3414 {
3415 753 thisffc.y = thisffc.y-wrap_bottom-32;
3416 753 thisffc.solid_update(false);
3417 753 thisffc.prev_changer_y = thisffc.x.getZLong();
3418 753 thisffc.changer_x = -1000;
3419 753 thisffc.changer_y = -1000;
3420 753 }
3421 else
3422 {
3423 91 zc_ffc_set(thisffc, 0);
3424 91 thisffc.flags&=~ffc_carryover;
3425 }
3426 844 }
3427 14941034 thisffc.solid_update();
3428 439854374 });
3429 14322874 }
3430 14347046 }
3431
3432 2098420 bool hitcombo(int32_t x, int32_t y, int32_t combotype, byte layers)
3433 {
3434
2/2
✓ Branch 0 taken 14685796 times.
✓ Branch 1 taken 2097896 times.
16783692 for(int q = 0; q < 7; ++q)
3435 {
3436
2/2
✓ Branch 0 taken 12587376 times.
✓ Branch 1 taken 2098420 times.
14685796 if(layers&(1<<q)) //if layer is to be checked
3437
2/2
✓ Branch 0 taken 2097896 times.
✓ Branch 1 taken 524 times.
2098420 if(COMBOTYPE2(q-1,x,y)==combotype) //matching type
3438 524 return true;
3439 14685272 }
3440 2097896 return false;
3441 2098420 }
3442
3443 419684 int gethitcombo(int32_t x, int32_t y, int32_t combotype, byte layers)
3444 {
3445
2/2
✓ Branch 0 taken 2937788 times.
✓ Branch 1 taken 419684 times.
3357472 for(int q = 0; q < 7; ++q)
3446 {
3447
2/2
✓ Branch 0 taken 2518104 times.
✓ Branch 1 taken 419684 times.
2937788 if(layers&(1<<q)) //if layer is to be checked
3448
1/2
✓ Branch 0 taken 419684 times.
✗ Branch 1 not taken.
419684 if(COMBOTYPE2(q-1,x,y)==combotype) //matching type
3449 return MAPCOMBO2(q-1,x,y);
3450 2937788 }
3451 419684 return -1;
3452 419684 }
3453
3454 bool hitflag(int32_t x, int32_t y, int32_t flagtype, byte layers)
3455 {
3456 for(int q = 0; q < 7; ++q)
3457 {
3458 if(layers&(1<<q)) //if layer is to be checked
3459 if(MAPFLAG2(q-1,x,y)==flagtype||MAPCOMBOFLAG2(q-1,x,y)==flagtype) //matching flag
3460 return true;
3461 }
3462 return false;
3463 }
3464
3465 229 optional<int> nextscr(int screen, int dir)
3466 {
3467 229 auto [m, s] = nextscr2(cur_map, screen, dir);
3468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 229 times.
229 if (m == -1) return nullopt;
3469 458 return (m<<7) + s;
3470 229 }
3471
3472 1056 std::pair<int32_t, int32_t> nextscr2(int32_t dir)
3473 {
3474 1056 int32_t map = cur_map;
3475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1056 times.
1056 int32_t screen = screenscrolling ? scrolling_hero_screen : hero_screen;
3476 1056 return nextscr2(map, screen, dir);
3477 }
3478
3479 5568 std::pair<int32_t, int32_t> nextscr2(int map, int screen, int32_t dir)
3480 {
3481 5568 screen = screen_index_direction(screen, (direction)dir);
3482
3483 // need to check for screens on other maps, 's' not valid, etc.
3484 5568 int32_t index = (hero_scr->sidewarpindex >> (dir*2))&3;
3485
3486 // Fun fact: when a scrolling warp is triggered, this function
3487 // is never even called! - Saf
3488
2/2
✓ Branch 0 taken 3318 times.
✓ Branch 1 taken 2250 times.
6112 if(hero_scr->sidewarptype[index] == 3) // scrolling warp
3489 {
3490
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 482 times.
✓ Branch 2 taken 525 times.
✓ Branch 3 taken 545 times.
✓ Branch 4 taken 698 times.
2250 switch(dir)
3491 {
3492 case up:
3493
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 399 times.
482 if(!(hero_scr->flags2&wfUP)) goto nowarp;
3494
3495 83 break;
3496
3497 case down:
3498
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 446 times.
525 if(!(hero_scr->flags2&wfDOWN)) goto nowarp;
3499
3500 79 break;
3501
3502 case left:
3503
2/2
✓ Branch 0 taken 209 times.
✓ Branch 1 taken 336 times.
545 if(!(hero_scr->flags2&wfLEFT)) goto nowarp;
3504
3505 209 break;
3506
3507 case right:
3508
2/2
✓ Branch 0 taken 173 times.
✓ Branch 1 taken 525 times.
698 if(!(hero_scr->flags2&wfRIGHT)) goto nowarp;
3509
3510 173 break;
3511 }
3512
3513 544 map = DMaps[hero_scr->sidewarpdmap[index]].map;
3514 544 screen = hero_scr->sidewarpscr[index] + DMaps[hero_scr->sidewarpdmap[index]].xoff;
3515 544 }
3516
3517 nowarp:
3518
4/4
✓ Branch 0 taken 5504 times.
✓ Branch 1 taken 64 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 5392 times.
5568 if(screen<0||screen>=128)
3519 176 return {-1, -1};
3520
3521 5392 return {map, screen};
3522 5568 }
3523
3524 399 optional<int> nextscr_mi(int mi, int dir)
3525 {
3526 399 int map = mi/MAPSCRSNORMAL;
3527 399 int screen = mi%MAPSCRSNORMAL;
3528 399 auto [m, s] = nextscr2(map, screen, dir);
3529
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 398 times.
399 if (m == -1) return nullopt;
3530 796 return (m<<7) + s;
3531 399 }
3532
3533 2103 void bombdoor(int32_t x,int32_t y)
3534 {
3535
2/2
✓ Branch 0 taken 2083 times.
✓ Branch 1 taken 20 times.
2103 if (!is_in_world_bounds(x, y))
3536 20 return;
3537
3538 2083 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, 0);
3539 2083 mapscr* scr = rpos_handle.scr;
3540 2083 int screen = scr->screen;
3541 2891 auto [x0, y0] = translate_screen_coordinates_to_world(rpos_handle.screen);
3542 #define CHECK_RECT(x,y,rx1,ry1,rx2,ry2) (isinRect(x,y,x0+rx1,y0+ry1,x0+rx2,y0+ry2))
3543
3544
12/12
✓ Branch 0 taken 77 times.
✓ Branch 1 taken 2006 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 67 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 67 times.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 67 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 67 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 67 times.
2083 if(scr->door[0]==dBOMB && CHECK_RECT(x,y,100,0,139,48))
3545 {
3546 67 scr->door[0]=dBOMBED;
3547 67 putdoor(scr, scrollbuf, 0, dBOMBED);
3548 67 setmapflag(scr, mDOOR_UP);
3549 67 markBmap(-1, screen);
3550
3551
1/2
✓ Branch 0 taken 67 times.
✗ Branch 1 not taken.
67 if(auto v = nextscr(screen, up))
3552 {
3553 67 setmapflag_mi(*v, mDOOR_DOWN);
3554 67 markBmap(-1,*v-(get_currdmap()<<7));
3555 67 }
3556 67 }
3557
3558
12/12
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 2034 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 39 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 39 times.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 39 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 39 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 39 times.
2083 if(scr->door[1]==dBOMB && CHECK_RECT(x,y,100,112,139,176))
3559 {
3560 39 scr->door[1]=dBOMBED;
3561 39 putdoor(scr, scrollbuf, 1, dBOMBED);
3562 39 setmapflag(scr, mDOOR_DOWN);
3563 39 markBmap(-1, rpos_handle.screen);
3564
3565
1/2
✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
39 if(auto v = nextscr(rpos_handle.screen, down))
3566 {
3567 39 setmapflag_mi(*v, mDOOR_UP);
3568 39 markBmap(-1,*v-(get_currdmap()<<7));
3569 39 }
3570 39 }
3571
3572
12/12
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 2016 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 51 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 51 times.
✓ Branch 6 taken 16 times.
✓ Branch 7 taken 51 times.
✓ Branch 8 taken 16 times.
✓ Branch 9 taken 51 times.
✓ Branch 10 taken 16 times.
✓ Branch 11 taken 51 times.
2083 if(scr->door[2]==dBOMB && CHECK_RECT(x,y,0,60,48,98))
3573 {
3574 51 scr->door[2]=dBOMBED;
3575 51 putdoor(scr, scrollbuf, 2, dBOMBED);
3576 51 setmapflag(scr, mDOOR_LEFT);
3577 51 markBmap(-1, rpos_handle.screen);
3578
3579
1/2
✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
51 if(auto v = nextscr(rpos_handle.screen, left))
3580 {
3581 51 setmapflag_mi(*v, mDOOR_RIGHT);
3582 51 markBmap(-1,*v-(get_currdmap()<<7));
3583 51 }
3584 51 }
3585
3586
12/12
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 1997 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 72 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 72 times.
✓ Branch 6 taken 14 times.
✓ Branch 7 taken 72 times.
✓ Branch 8 taken 14 times.
✓ Branch 9 taken 72 times.
✓ Branch 10 taken 14 times.
✓ Branch 11 taken 72 times.
2083 if(scr->door[3]==dBOMB && CHECK_RECT(x,y,192,60,240,98))
3587 {
3588 72 scr->door[3]=dBOMBED;
3589 72 putdoor(scr, scrollbuf, 3, dBOMBED);
3590 72 setmapflag(scr, mDOOR_RIGHT);
3591 72 markBmap(-1, rpos_handle.screen);
3592
3593
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(auto v = nextscr(rpos_handle.screen, right))
3594 {
3595 72 setmapflag_mi(*v, mDOOR_LEFT);
3596 72 markBmap(-1,*v-(get_currdmap()<<7));
3597 72 }
3598 72 }
3599 2103 }
3600
3601 6357987791 void draw_cmb(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset,
3602 bool over, bool transp)
3603 {
3604 6357987791 auto& cmb = combobuf[cid];
3605
2/2
✓ Branch 0 taken 196956 times.
✓ Branch 1 taken 6357790835 times.
6357987791 if(cmb.animflags & AF_EDITOR_ONLY)
3606 196956 return;
3607
2/2
✓ Branch 0 taken 3295216732 times.
✓ Branch 1 taken 3062574103 times.
6357790835 if(over)
3608 {
3609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3295216732 times.
3295216732 if(cmb.animflags & AF_TRANSPARENT)
3610 transp = !transp;
3611
2/2
✓ Branch 0 taken 319148412 times.
✓ Branch 1 taken 2976068320 times.
3295216732 if(transp)
3612 319148412 overcombotranslucent(dest, x, y, cid, cset, 128);
3613 2976068320 else overcombo(dest, x, y, cid, cset);
3614 3295216732 }
3615 3062574103 else putcombo(dest, x, y, cid, cset);
3616 6357987791 }
3617 6357996239 void draw_cmb_pos(BITMAP* dest, int32_t x, int32_t y, rpos_t rpos, int32_t cid,
3618 int32_t cset, byte layer, bool over, bool transp)
3619 {
3620
2/2
✓ Branch 0 taken 745902785 times.
✓ Branch 1 taken 5612093454 times.
6357996239 if (rpos != rpos_t::None)
3621 {
3622 5612093454 rpos_t plrpos = COMBOPOS_REGION_B(Hero.x+8, Hero.y+8);
3623
2/2
✓ Branch 0 taken 742953 times.
✓ Branch 1 taken 5611350501 times.
5612093454 if (plrpos != rpos_t::None)
3624 {
3625 5611350501 bool dosw = false;
3626
4/4
✓ Branch 0 taken 52860 times.
✓ Branch 1 taken 5611297641 times.
✓ Branch 2 taken 44412 times.
✓ Branch 3 taken 8448 times.
5611350501 if (rpos == hooked_comborpos && (hooked_layerbits & (1<<layer)))
3627 {
3628
1/2
✓ Branch 0 taken 8448 times.
✗ Branch 1 not taken.
8448 if(hooked_undercombos[layer] > -1)
3629 {
3630 draw_cmb(dest, x, y,
3631 hooked_undercombos[layer], hooked_undercombos[layer+7], over, transp);
3632 }
3633 8448 dosw = true;
3634 8448 }
3635
4/4
✓ Branch 0 taken 31851632 times.
✓ Branch 1 taken 5579490421 times.
✓ Branch 2 taken 8448 times.
✓ Branch 3 taken 31843184 times.
5611342053 else if (rpos == plrpos && (hooked_layerbits & (1<<(layer+8))))
3636 {
3637 8448 dosw = true;
3638 8448 }
3639
2/2
✓ Branch 0 taken 5611333605 times.
✓ Branch 1 taken 16896 times.
5611350501 if (dosw)
3640 {
3641
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 16896 times.
✗ Branch 3 not taken.
16896 switch (Hero.switchhookstyle)
3642 {
3643 default: case swPOOF:
3644 break; //Nothing special here
3645 case swFLICKER:
3646 {
3647
2/2
✓ Branch 0 taken 8448 times.
✓ Branch 1 taken 8448 times.
16896 if(abs(Hero.switchhookclk-33)&0b1000)
3648 8448 break; //Drawn this frame
3649 8448 return; //Not drawn this frame
3650 }
3651 case swRISE:
3652 {
3653 //Draw rising up
3654 y -= 8-(abs(Hero.switchhookclk-32)/4);
3655 break;
3656 }
3657 }
3658 8448 }
3659 5611342053 }
3660 5612085006 }
3661
3662 6357987791 draw_cmb(dest, x, y, cid, cset, over, transp);
3663 6357996239 }
3664
3665 // `draw_cmb_pos` only does meaningful work if the combo being drawn is within the bounds of
3666 // the `bmp` bitmap. However, even getting to the point where `puttile16` (for example) knows
3667 // to cull is somewhat expensive. Since it can only draw 16x16 pixels, we can do the equivalent
3668 // culling here by determining the rows/columns that are within the bitmap bounds. This nets
3669 // on the order of ~30 FPS in uncapped mode on my machine, depending on the viewport/region size.
3670 //
3671 // These two inequalities must be true for `draw_cmb_pos` to do anything useful:
3672 //
3673 // -16 < comboPositionX*16 + x < bitmapWidth
3674 // -16 < comboPositionY*16 + y < bitmapHeight
3675 //
3676 // The following start/end values are derived directly from the above.
3677 //
3678 // `x` and `y` are the offsets the combos will be drawn into the bitmap.
3679 39319196 static void get_bounds_for_draw_cmb_calls(BITMAP* bmp, int x, int y, int& start_x, int& end_x, int& start_y, int& end_y)
3680 {
3681 // if (bmp->clip)
3682 // {
3683 // start_x = MAX(0, ceil((bmp->cl - 15 - x) / 16.0));
3684 // end_x = MIN(16, ceil((bmp->cr - x) / 16.0));
3685 // start_y = MAX(0, ceil((bmp->ct - 15 - y) / 16.0));
3686 // end_y = MIN(11, ceil((bmp->cb - y) / 16.0));
3687 // return;
3688 // }
3689
3690
2/2
✓ Branch 0 taken 2161388 times.
✓ Branch 1 taken 37157808 times.
39319196 start_x = MAX(0, ceil((-15 - x) / 16.0));
3691
2/2
✓ Branch 0 taken 2170926 times.
✓ Branch 1 taken 37148270 times.
39319196 end_x = MIN(16, ceil((bmp->w - x) / 16.0));
3692
2/2
✓ Branch 0 taken 37936342 times.
✓ Branch 1 taken 1382854 times.
39319196 start_y = MAX(0, ceil((-15 - y) / 16.0));
3693
2/2
✓ Branch 0 taken 1669929 times.
✓ Branch 1 taken 37649267 times.
39319196 end_y = MIN(11, ceil((bmp->h - y) / 16.0));
3694 39319196 }
3695
3696 186297164 void do_ffc_layer(BITMAP* bmp, int32_t layer, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3697 {
3698
1/2
✓ Branch 0 taken 186297164 times.
✗ Branch 1 not taken.
186297164 if(!show_ffcs) return;
3699 186297164 mapscr* scr = screen_handle.scr;
3700 186297164 mapscr* base_scr = screen_handle.base_scr;
3701
3702 186297164 y += playing_field_offset;
3703
3704 186297164 bool is_bg_layer = layer < -1;
3705
2/2
✓ Branch 0 taken 33805963 times.
✓ Branch 1 taken 152491201 times.
186297164 int real_layer = is_bg_layer ? abs(layer) : layer;
3706
2/2
✓ Branch 0 taken 186297164 times.
✓ Branch 1 taken 5558088178 times.
5744385342 for(int32_t i = (base_scr->numFFC()-1); i >= 0; --i)
3707 {
3708
2/2
✓ Branch 0 taken 5352590878 times.
✓ Branch 1 taken 205497300 times.
5558088178 if (base_scr->ffcs[i].data == 0)
3709 5352590878 continue;
3710
4/4
✓ Branch 0 taken 37360890 times.
✓ Branch 1 taken 168136410 times.
✓ Branch 2 taken 18682926 times.
✓ Branch 3 taken 18677964 times.
205497300 if(real_layer == 2 && (is_bg_layer != XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG)))
3711 18677964 continue;
3712
4/4
✓ Branch 0 taken 37360890 times.
✓ Branch 1 taken 149458446 times.
✓ Branch 2 taken 18682926 times.
✓ Branch 3 taken 18677964 times.
186819336 else if (real_layer == 3 && (is_bg_layer != XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)))
3713 18677964 continue;
3714
4/4
✓ Branch 0 taken 149463408 times.
✓ Branch 1 taken 18677964 times.
✓ Branch 2 taken 18682926 times.
✓ Branch 3 taken 130780482 times.
168141372 if (real_layer > -1 && base_scr->ffcs[i].layer != real_layer)
3715 130780482 continue;
3716
3717
6/6
✓ Branch 0 taken 3008970 times.
✓ Branch 1 taken 34351920 times.
✓ Branch 2 taken 5110 times.
✓ Branch 3 taken 3003860 times.
✓ Branch 4 taken 2626 times.
✓ Branch 5 taken 2484 times.
37360890 if (screenscrolling && (base_scr->ffcs[i].flags & ffc_carryover) != 0 && screen_handle.screen != scrolling_hero_screen)
3718 2484 continue; //If scrolling, only draw carryover ffcs from newscr and not oldscr.
3719
3720 37358406 base_scr->ffcs[i].draw_ffc(bmp, x, y, (layer==-1));
3721 37358406 }
3722 186297164 }
3723 170267196 void _do_current_ffc_layer(BITMAP* bmp, int32_t layer)
3724 {
3725
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 170267196 times.
170267196 if(!show_ffcs) return;
3726 345112614 for_every_base_screen_in_region([&](mapscr* base_scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3727 174845418 screen_handle_t handle = {base_scr, base_scr, base_scr->screen, 0};
3728 174845418 do_ffc_layer(bmp, layer, handle, 0, 0);
3729 174845418 });
3730 170267196 }
3731 74266949 void do_scrolling_layer(BITMAP *bmp, int32_t type, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3732 {
3733 74266949 mapscr* scr = screen_handle.scr;
3734 74266949 mapscr* base_scr = screen_handle.base_scr;
3735
3736
4/4
✓ Branch 0 taken 60718705 times.
✓ Branch 1 taken 13548244 times.
✓ Branch 2 taken 13548244 times.
✓ Branch 3 taken 74266949 times.
74266949 if (type == -3 || type == -4)
3737 {
3738 27096488 y += playing_field_offset;
3739
3740
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
27096488 for(int32_t i = (base_scr->numFFC()-1); i >= 0; --i)
3741 {
3742 if (base_scr->ffcs[i].data == 0)
3743 continue;
3744
3745 if (screenscrolling && (base_scr->ffcs[i].flags & ffc_carryover) != 0 && screen_handle.screen != scrolling_hero_screen)
3746 continue; //If scrolling, only draw carryover ffcs from newscr and not oldscr.
3747
3748 base_scr->ffcs[i].draw_ffc(bmp, x, y, (type==-4));
3749 }
3750 return;
3751 }
3752
3753 74266949 x -= viewport.x;
3754 74266949 y -= viewport.y - playing_field_offset;
3755
3756 74266949 bool over = true, transp = false;
3757 74266949 int layer = screen_handle.layer;
3758
3759
7/8
✓ Branch 0 taken 53887731 times.
✓ Branch 1 taken 20379218 times.
✓ Branch 2 taken 13097278 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 32986239 times.
✓ Branch 5 taken 20901492 times.
✓ Branch 6 taken 3065892 times.
✓ Branch 7 taken 4216048 times.
74266949 switch(type ? type : layer)
3760 {
3761 case -2: //push blocks
3762
2/2
✓ Branch 0 taken 19437995 times.
✓ Branch 1 taken 13548244 times.
32986239 if (scr)
3763 {
3764
2/2
✓ Branch 0 taken 3421087120 times.
✓ Branch 1 taken 23070359 times.
3417720331 for(int32_t i=0; i<176; i++)
3765 {
3766 3421087120 int32_t mf=scr->sflag[i], mf2 = combobuf[scr->data[i]].flag;
3767
3768
10/10
✓ Branch 0 taken 3420917451 times.
✓ Branch 1 taken 169669 times.
✓ Branch 2 taken 3419450179 times.
✓ Branch 3 taken 1467272 times.
✓ Branch 4 taken 3418821816 times.
✓ Branch 5 taken 628363 times.
✓ Branch 6 taken 24409904 times.
✓ Branch 7 taken 3394411912 times.
✓ Branch 8 taken 42741087 times.
✓ Branch 9 taken 13927023 times.
3458134588 if(mf==mfPUSHUD || mf==mfPUSH4 || mf==mfPUSHED || ((mf>=mfPUSHLR)&&(mf<=mfPUSHRINS))
3769
6/8
✓ Branch 0 taken 3415940286 times.
✓ Branch 1 taken 21528374 times.
✓ Branch 2 taken 3415940286 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3415940286 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 37047468 times.
✓ Branch 7 taken 3378892818 times.
3418821816 || mf2==mfPUSHUD || mf2==mfPUSH4 || mf2==mfPUSHED || ((mf2>=mfPUSHLR)&&(mf2<=mfPUSHRINS)))
3770 {
3771
4/4
✓ Branch 0 taken 4767611 times.
✓ Branch 1 taken 694884 times.
✓ Branch 2 taken 3657 times.
✓ Branch 3 taken 4763954 times.
90944669 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3772 5462495 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, true, false);
3773 5462495 }
3774 3398282336 }
3775 23070359 }
3776 36618603 return;
3777
3778 case -1: //over combo
3779
1/2
✓ Branch 0 taken 20901492 times.
✗ Branch 1 not taken.
20901492 if (scr)
3780 {
3781
2/2
✓ Branch 0 taken 3678662592 times.
✓ Branch 1 taken 20901492 times.
3699564084 for(int32_t i=0; i<176; i++)
3782 {
3783
2/2
✓ Branch 0 taken 3659563800 times.
✓ Branch 1 taken 19098792 times.
3678662592 if(combo_class_buf[combobuf[scr->data[i]].type].overhead)
3784 {
3785
4/4
✓ Branch 0 taken 15392788 times.
✓ Branch 1 taken 3706004 times.
✓ Branch 2 taken 22320 times.
✓ Branch 3 taken 15370468 times.
19098792 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3786 19098792 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, true, false);
3787 19098792 }
3788 3678662592 }
3789 20901492 }
3790 20901492 return;
3791
3792 case 1:
3793 case 4:
3794 case 5:
3795 case 6:
3796
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 13097278 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
13097278 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3797 {
3798
1/2
✓ Branch 0 taken 13097278 times.
✗ Branch 1 not taken.
13097278 if (scr)
3799 {
3800
2/2
✓ Branch 0 taken 11438067 times.
✓ Branch 1 taken 1659211 times.
13097278 if(base_scr->layeropacity[layer-1]!=255)
3801 1659211 transp = true;
3802 13097278 break;
3803 }
3804 }
3805 return;
3806
3807 case 2:
3808
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3065892 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3065892 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3809 {
3810
1/2
✓ Branch 0 taken 3065892 times.
✗ Branch 1 not taken.
3065892 if (scr)
3811 {
3812
2/2
✓ Branch 0 taken 2846295 times.
✓ Branch 1 taken 219597 times.
3065892 if(base_scr->layeropacity[layer-1]!=255)
3813 219597 transp = true;
3814
3815
2/2
✓ Branch 0 taken 2936982 times.
✓ Branch 1 taken 128910 times.
3065892 if(XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3816 128910 over = false;
3817
3818 3065892 break;
3819 }
3820 }
3821 return;
3822
3823 case 3:
3824
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4216048 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4216048 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3825 {
3826
1/2
✓ Branch 0 taken 4216048 times.
✗ Branch 1 not taken.
4216048 if (scr)
3827 {
3828
2/2
✓ Branch 0 taken 4142335 times.
✓ Branch 1 taken 73713 times.
4216048 if(base_scr->layeropacity[layer-1]!=255)
3829 73713 transp = true;
3830
3831
2/2
✓ Branch 0 taken 36655 times.
✓ Branch 1 taken 60483 times.
4216048 if(XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)
3832
2/2
✓ Branch 0 taken 97138 times.
✓ Branch 1 taken 4118910 times.
4216048 && !XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3833 60483 over = false;
3834
3835 4216048 break;
3836 }
3837 }
3838 return;
3839 }
3840
3841 int start_x, end_x, start_y, end_y;
3842 20379218 get_bounds_for_draw_cmb_calls(bmp, x, y, start_x, end_x, start_y, end_y);
3843
2/2
✓ Branch 0 taken 20379218 times.
✓ Branch 1 taken 216079081 times.
236458299 for (int cy = start_y; cy < end_y; cy++)
3844 {
3845
2/2
✓ Branch 0 taken 3269886817 times.
✓ Branch 1 taken 216079081 times.
3485965898 for (int cx = start_x; cx < end_x; cx++)
3846 {
3847 3269886817 int i = cx + cy*16;
3848
4/4
✓ Branch 0 taken 2894426060 times.
✓ Branch 1 taken 375460757 times.
✓ Branch 2 taken 10227360 times.
✓ Branch 3 taken 2884198700 times.
3269886817 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3849 3269886817 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, over, transp);
3850 3269886817 }
3851 216079081 }
3852 60718705 }
3853
3854 267929256 bool lenscheck(mapscr* scr, int layer)
3855 {
3856
4/4
✓ Branch 0 taken 267750308 times.
✓ Branch 1 taken 178948 times.
✓ Branch 2 taken 178948 times.
✓ Branch 3 taken 267929256 times.
267929256 if(layer < 0 || layer > 6) return true;
3857
2/2
✓ Branch 0 taken 258430197 times.
✓ Branch 1 taken 9499059 times.
267929256 if(get_qr(qr_OLD_LENS_LAYEREFFECT))
3858 {
3859
2/2
✓ Branch 0 taken 208774261 times.
✓ Branch 1 taken 49655936 times.
258430197 if(!layer) return true;
3860
8/8
✓ Branch 0 taken 34766337 times.
✓ Branch 1 taken 174007924 times.
✓ Branch 2 taken 258970 times.
✓ Branch 3 taken 34507367 times.
✓ Branch 4 taken 143758 times.
✓ Branch 5 taken 163336 times.
✓ Branch 6 taken 326536 times.
✓ Branch 7 taken 34324589 times.
208774261 if((layer==(int32_t)(scr->lens_layer&7)+1) && ((scr->lens_layer&llLENSSHOWS && !lensclk) || (scr->lens_layer&llLENSHIDES && lensclk)))
3861 489872 return false;
3862 208332513 }
3863 else
3864 {
3865
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9499059 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9499059 times.
9499059 if((lensclk ? scr->lens_hide : scr->lens_show) & (1<<layer))
3866 return false;
3867 }
3868 217831572 return true;
3869 267750308 }
3870
3871 155553257 void do_layer(BITMAP *bmp, int32_t type, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3872 {
3873 155553257 bool showlayer = true;
3874 155553257 mapscr* base_scr = screen_handle.base_scr;
3875 155553257 int layer = screen_handle.layer;
3876
2/2
✓ Branch 0 taken 41935937 times.
✓ Branch 1 taken 113617320 times.
155553257 int target = type ? type : layer;
3877
3/4
✓ Branch 0 taken 113617320 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20147903 times.
✓ Branch 3 taken 21788034 times.
155553257 switch(target)
3878 {
3879 case -2:
3880
1/2
✓ Branch 0 taken 20147903 times.
✗ Branch 1 not taken.
20147903 if(!show_layer_push)
3881 showlayer = false;
3882 20147903 break;
3883
3884 case -1:
3885
1/2
✓ Branch 0 taken 21788034 times.
✗ Branch 1 not taken.
21788034 if(!show_layer_over)
3886 showlayer = false;
3887 21788034 break;
3888
3889 case 1: case 2: case 3:
3890 case 4: case 5: case 6:
3891 113617320 showlayer = show_layers[target];
3892 113617320 break;
3893 }
3894
3895
2/2
✓ Branch 0 taken 41935937 times.
✓ Branch 1 taken 113617320 times.
155553257 if(!type)
3896 {
3897
2/2
✓ Branch 0 taken 113481122 times.
✓ Branch 1 taken 136198 times.
113617320 if(!lenscheck(base_scr,layer))
3898 136198 showlayer = false;
3899 113617320 }
3900
3901
2/2
✓ Branch 0 taken 136198 times.
✓ Branch 1 taken 155417059 times.
155553257 if(showlayer)
3902 {
3903
6/6
✓ Branch 0 taken 60774828 times.
✓ Branch 1 taken 94642231 times.
✓ Branch 2 taken 20435341 times.
✓ Branch 3 taken 40339487 times.
✓ Branch 4 taken 56123 times.
✓ Branch 5 taken 20379218 times.
155417059 if (screen_handle.scr && (type || !(base_scr->hidelayers & (1 << (layer)))))
3904 {
3905 60718705 do_scrolling_layer(bmp, type, screen_handle, x, y);
3906
4/4
✓ Branch 0 taken 20379218 times.
✓ Branch 1 taken 40339487 times.
✓ Branch 2 taken 19129566 times.
✓ Branch 3 taken 1249652 times.
60718705 if(!type && !get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3907
2/2
✓ Branch 0 taken 1249076 times.
✓ Branch 1 taken 576 times.
1250228 if(mblock2.draw(bmp,layer))
3908 576 do_primitives(bmp, SPLAYER_MOVINGBLOCK);
3909 60718705 }
3910 155417059 }
3911 155553257 }
3912
3913 102614415 void do_layer_primitives(BITMAP *bmp, int32_t layer)
3914 {
3915 102614415 bool showlayer = true;
3916
3917
2/4
✓ Branch 0 taken 102614415 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 102614415 times.
102614415 if(layer >= 0 && layer <= 6)
3918 {
3919 102614415 showlayer = show_layers[layer];
3920
3921
2/2
✓ Branch 0 taken 102487813 times.
✓ Branch 1 taken 126602 times.
102614415 if(!lenscheck(origin_scr,layer))
3922 126602 showlayer = false;
3923 102614415 }
3924
3925
2/2
✓ Branch 0 taken 126602 times.
✓ Branch 1 taken 102487813 times.
102614415 if (showlayer)
3926 102487813 do_primitives(bmp, layer);
3927 102614415 }
3928
3929 // Called by do_walkflags
3930 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,int32_t xofs,int32_t yofs, word cmbdat,int32_t lyr)
3931 {
3932 newcombo const &c = combobuf[cmbdat];
3933
3934 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
3935
3936 int32_t xx = x-xofs;
3937 int32_t yy = y+playing_field_offset-yofs;
3938
3939 int32_t bridgedetected = 0;
3940
3941 for(int32_t i=0; i<4; i++)
3942 {
3943 int32_t tx=((i&2)<<2)+xx - viewport.x;
3944 int32_t ty=((i&1)<<3)+yy - viewport.y;
3945 int32_t tx2=((i&2)<<2)+x - viewport.x;
3946 int32_t ty2=((i&1)<<3)+y - viewport.y;
3947 for (int32_t j = lyr-1; j <= 1; j++)
3948 {
3949 if (get_qr(qr_OLD_BRIDGE_COMBOS))
3950 {
3951 if (combobuf[MAPCOMBO2(j,tx2,ty2)].type == cBRIDGE && !_walkflag_layer(tx2,ty2,j))
3952 {
3953 bridgedetected |= (1<<i);
3954 }
3955 }
3956 else
3957 {
3958 if (combobuf[MAPCOMBO2(j,tx2,ty2)].type == cBRIDGE && _effectflag_layer(tx2,ty2,j))
3959 {
3960 bridgedetected |= (1<<i);
3961 }
3962 }
3963 }
3964 if ((bridgedetected & (1<<i)))
3965 {
3966 if (i >= 3) break;
3967 else continue;
3968 }
3969 bool doladdercheck = true;
3970
3971 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
3972 {
3973 for(int32_t k=0; k<8; k+=2)
3974 for(int32_t j=0; j<8; j+=2)
3975 if(((k+j)/2)%2)
3976 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,makecol(85,85,255));
3977 }
3978 if (iswater_type(c.type) && !DRIEDLAKE && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) //Yes, I realize this is horribly inaccurate; the alternative is the game chugging every time you turn on walk cheats.
3979 {
3980 if (get_qr(qr_NO_SOLID_SWIM)) doladdercheck = false;
3981 if((lyr==0 || (get_qr(qr_WATER_ON_LAYER_1) && lyr == 1) || (get_qr(qr_WATER_ON_LAYER_2) && lyr == 2)) && get_qr(qr_DROWN))
3982 rectfill(dest,tx,ty,tx+7,ty+7,makecol(85,85,255));
3983 else rectfill(dest,tx,ty,tx+7,ty+7,makecol(170,170,170));
3984 }
3985
3986 if(c.walk&(1<<i) && !(iswater_type(c.type) && DRIEDLAKE) && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) // Check for dried lake (watertype && not water)
3987 {
3988 if(c.type==cLADDERHOOKSHOT && isstepable(cmbdat) && ishookshottable(xx,yy))
3989 {
3990 for(int32_t k=0; k<8; k+=2)
3991 for(int32_t j=0; j<8; j+=2)
3992 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,((k+j)/2)%2 ? makecol(165,105,8) : makecol(170,170,170));
3993 }
3994 else
3995 {
3996 int32_t color = makecol(178,36,36);
3997
3998 if(isstepable(cmbdat)&& (!doladdercheck))
3999 color=makecol(165,105,8);
4000 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(xx,yy))
4001 color=makecol(170,170,170);
4002
4003 rectfill(dest,tx,ty,tx+7,ty+7,color);
4004 }
4005 }
4006 }
4007
4008 // Draw damage combos
4009 bool dmg = combo_class_buf[combobuf[MAPCOMBO2(-1,xx,yy)].type].modify_hp_amount
4010 || combo_class_buf[combobuf[MAPCOMBO2(0,xx,yy)].type].modify_hp_amount
4011 || combo_class_buf[combobuf[MAPCOMBO2(1,xx,yy)].type].modify_hp_amount;
4012
4013 if(dmg)
4014 {
4015 int32_t color = makecol(255,255,0);
4016 if (bridgedetected <= 0)
4017 {
4018 for(int32_t k=0; k<16; k+=2)
4019 for(int32_t j=0; j<16; j+=2)
4020 if(((k+j)/2)%2)
4021 {
4022 int32_t x0 = x - viewport.x;
4023 int32_t y0 = y - viewport.y;
4024 rectfill(dest,x0+k,y0+j,x0+k+1,y0+j+1,color);
4025 }
4026 }
4027 else
4028 {
4029 for(int32_t i=0; i<4; i++)
4030 {
4031 if (!(bridgedetected & (1<<i)))
4032 {
4033 int32_t tx=((i&2)<<2)+x - viewport.x;
4034 int32_t ty=((i&1)<<3)+y - viewport.y;
4035 for(int32_t k=0; k<8; k+=2)
4036 for(int32_t j=0; j<8; j+=2)
4037 if((k+j)%4 < 2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,color);
4038 }
4039 }
4040 }
4041 }
4042 }
4043 static void put_walkflags_a5(int32_t x, int32_t y, word cmbdat, int32_t lyr)
4044 {
4045 ALLEGRO_COLOR col_solid = al_map_rgba(178,36,36,info_opacity);
4046 ALLEGRO_COLOR col_water1 = al_map_rgba(85,85,255,info_opacity);
4047 ALLEGRO_COLOR col_lhook = al_map_rgba(170,170,170,info_opacity);
4048 ALLEGRO_COLOR col_stepable = al_map_rgba(165,105,8,info_opacity);
4049 ALLEGRO_COLOR col_dmg = al_map_rgba(255,255,0,info_opacity);
4050 newcombo const &c = combobuf[cmbdat];
4051
4052 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
4053
4054 int32_t xx = x-viewport.x;
4055 int32_t yy = y+playing_field_offset-viewport.y;
4056
4057 int32_t bridgedetected = 0;
4058
4059 // Draw damage combos
4060 bool dmg = combo_class_buf[c.type].modify_hp_amount;
4061
4062 for(int32_t i=0; i<4; i++)
4063 {
4064 int32_t tx=((i&2)<<2)+xx;
4065 int32_t ty=((i&1)<<3)+yy;
4066 int32_t tx2=((i&2)<<2)+x;
4067 int32_t ty2=((i&1)<<3)+y;
4068 for (int32_t m = lyr-1; m <= 1; m++)
4069 {
4070 if (get_qr(qr_OLD_BRIDGE_COMBOS))
4071 {
4072 if (m >= 0 && combobuf[MAPCOMBO2(m, tx2, ty2)].type == cBRIDGE && !_walkflag_layer(tx2, ty2, m))
4073 {
4074 bridgedetected |= (1<<i);
4075 }
4076 }
4077 else
4078 {
4079 if (m >= 0 && combobuf[MAPCOMBO2(m, tx2, ty2)].type == cBRIDGE && _effectflag_layer(tx2, ty2, m))
4080 {
4081 bridgedetected |= (1<<i);
4082 }
4083 }
4084 }
4085 if ((bridgedetected & (1<<i)))
4086 continue;
4087 bool doladdercheck = true;
4088
4089 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
4090 {
4091 for(int32_t k=0; k<8; k+=2)
4092 for(int32_t j=0; j<8; j+=2)
4093 if(((k+j)/2)%2)
4094 al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,col_water1);
4095 }
4096 if (iswater_type(c.type) && !DRIEDLAKE && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) //Yes, I realize this is horribly inaccurate; the alternative is the game chugging every time you turn on walk cheats.
4097 {
4098 if (get_qr(qr_NO_SOLID_SWIM)) doladdercheck = false;
4099 if((lyr==0 || (get_qr(qr_WATER_ON_LAYER_1) && lyr == 1) || (get_qr(qr_WATER_ON_LAYER_2) && lyr == 2)) && get_qr(qr_DROWN))
4100 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_water1);
4101 else al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_lhook);
4102 }
4103
4104 if(c.walk&(1<<i) && !(iswater_type(c.type) && DRIEDLAKE) && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) // Check for dried lake (watertype && not water)
4105 {
4106 if(c.type==cLADDERHOOKSHOT && isstepable(cmbdat) && ishookshottable(xx,yy))
4107 {
4108 for(int32_t k=0; k<8; k+=2)
4109 for(int32_t j=0; j<8; j+=2)
4110 al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,((k+j)/2)%2 ? col_stepable : col_lhook);
4111 }
4112 else
4113 {
4114 ALLEGRO_COLOR* color = &col_solid;
4115
4116 if(isstepable(cmbdat)&& (!doladdercheck))
4117 color=&col_stepable;
4118 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(xx,yy))
4119 color=&col_lhook;
4120
4121 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,*color);
4122 }
4123 }
4124
4125 if(dmg)
4126 {
4127 for(int32_t k=0; k<8; k+=2)
4128 for(int32_t j=0; j<8; j+=2)
4129 if((k+j)%4 < 2) al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,col_dmg);
4130 }
4131 }
4132 }
4133
4134 void put_effectflags(BITMAP *dest,int32_t x,int32_t y,int32_t xofs,int32_t yofs, word cmbdat,int32_t lyr)
4135 {
4136 newcombo const &c = combobuf[cmbdat];
4137
4138 int32_t xx = x-xofs-viewport.x;
4139 int32_t yy = y+playing_field_offset-yofs-viewport.y;
4140
4141 for(int32_t i=0; i<4; i++)
4142 {
4143 int32_t tx=((i&2)<<2)+xx;
4144 int32_t ty=((i&1)<<3)+yy;
4145
4146 if(((c.walk>>4)&(1<<i)) && c.type != cNONE)
4147 {
4148 int32_t color = vc(10);
4149
4150 rectfill(dest,tx,ty,tx+7,ty+7,color);
4151 }
4152 }
4153 }
4154 static void put_effectflags_a5(int32_t x, int32_t y, word cmbdat, int32_t lyr)
4155 {
4156 ALLEGRO_COLOR col_eff = al_map_rgba(85,255,85,info_opacity);
4157 newcombo const &c = combobuf[cmbdat];
4158
4159 int32_t xx = x-viewport.x;
4160 int32_t yy = y+playing_field_offset-viewport.y;
4161
4162 for(int32_t i=0; i<4; i++)
4163 {
4164 int32_t tx=((i&2)<<2)+xx;
4165 int32_t ty=((i&1)<<3)+yy;
4166
4167 if(((c.walk>>4)&(1<<i)) && c.type != cNONE)
4168 {
4169 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_eff);
4170 }
4171 }
4172 }
4173
4174 void draw_ladder_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
4175 {
4176 for(auto cx = 0; cx < 256; cx += 16)
4177 {
4178 for(auto cy = 0; cy < 176; cy += 16)
4179 {
4180 if(isSVLadder(cx,cy))
4181 {
4182 auto nx = cx+x, ny = cy+y;
4183 if(cy && !isSVLadder(cx,cy-16))
4184 line(dest,nx,ny,nx+15,ny,c);
4185 rectfill(dest,nx,ny,nx+3,ny+15,c);
4186 rectfill(dest,nx+12,ny,nx+15,ny+15,c);
4187 rectfill(dest,nx+4,ny+2,nx+11,ny+5,c);
4188 rectfill(dest,nx+4,ny+10,nx+11,ny+13,c);
4189 }
4190 else if(isSVPlatform(cx,cy))
4191 {
4192 line(dest,cx+x,cy+y,cx+x+15,cy+y,c);
4193 }
4194 }
4195 }
4196 }
4197 void draw_ladder_platform_a5(int32_t x, int32_t y, ALLEGRO_COLOR c)
4198 {
4199 for(auto cx = 0; cx < 256; cx += 16)
4200 {
4201 for(auto cy = 0; cy < 176; cy += 16)
4202 {
4203 if(isSVLadder(cx,cy))
4204 {
4205 auto nx = cx+x, ny = cy+y;
4206 if(cy && !isSVLadder(cx,cy-16))
4207 al_draw_line(nx,ny,nx+15,ny,c,1);
4208 al_draw_filled_rectangle(nx,ny,nx+4,ny+16,c);
4209 al_draw_filled_rectangle(nx+12,ny,nx+16,ny+16,c);
4210 al_draw_filled_rectangle(nx+4,ny+2,nx+12,ny+6,c);
4211 al_draw_filled_rectangle(nx+4,ny+10,nx+12,ny+14,c);
4212 }
4213 else if(isSVPlatform(cx,cy))
4214 {
4215 al_draw_line(cx+x,cy+y,cx+x+15,cy+y,c,1);
4216 }
4217 }
4218 }
4219 }
4220
4221 // Walkflags L4 cheat
4222 void do_walkflags(const screen_handles_t& screen_handles, int32_t x, int32_t y)
4223 {
4224 if (!show_walkflags)
4225 return;
4226
4227 start_info_bmp();
4228
4229 mapscr* scr = screen_handles[0].scr;
4230 for(int32_t i=0; i<176; i++)
4231 {
4232 put_walkflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], 0);
4233 }
4234
4235 for(int32_t k=0; k<2; k++)
4236 {
4237 scr = screen_handles[k + 1].scr;
4238
4239 if (scr)
4240 {
4241 for(int32_t i=0; i<176; i++)
4242 {
4243 put_walkflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], k%2+1);
4244 }
4245 }
4246 }
4247
4248 end_info_bmp();
4249 }
4250
4251 void do_walkflags(int32_t x, int32_t y)
4252 {
4253 if (!show_walkflags)
4254 return;
4255
4256 x += -viewport.x;
4257 y += playing_field_offset - viewport.y;
4258
4259 start_info_bmp();
4260
4261 draw_ladder_platform_a5(x,y,al_map_rgba(165,105,8,info_opacity));
4262 draw_solid_objects_a5(x,y,al_map_rgba(178,36,36,info_opacity));
4263 draw_slopes_a5(x,y,al_map_rgba(255,85,255,info_opacity));
4264
4265 end_info_bmp();
4266 }
4267
4268 // Effectflags L4 cheat
4269 void do_effectflags(mapscr* scr, int32_t x, int32_t y)
4270 {
4271 if(show_effectflags)
4272 {
4273 start_info_bmp();
4274
4275 for(int32_t i=0; i<176; i++)
4276 {
4277 put_effectflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], 0);
4278 }
4279
4280 end_info_bmp();
4281 }
4282 }
4283
4284 272141 void calc_darkroom_combos(mapscr* scr, int offx, int offy)
4285 {
4286 272141 int map = scr->map;
4287 272141 int screen = scr->screen;
4288
4289
2/2
✓ Branch 0 taken 1904987 times.
✓ Branch 1 taken 272141 times.
2177128 for(int32_t lyr = 0; lyr < 7; ++lyr)
4290 {
4291 1904987 mapscr* scr = get_scr_layer(map, screen, lyr);
4292
2/2
✓ Branch 0 taken 780869 times.
✓ Branch 1 taken 1124118 times.
1904987 if (!scr->is_valid()) continue;
4293
4294
2/2
✓ Branch 0 taken 137432944 times.
✓ Branch 1 taken 780869 times.
138213813 for(int32_t q = 0; q < 176; ++q)
4295 {
4296 137432944 newcombo const& cmb = combobuf[scr->data[q]];
4297
2/2
✓ Branch 0 taken 136828325 times.
✓ Branch 1 taken 604619 times.
137432944 if(cmb.type == cTORCH)
4298 {
4299 604619 do_torch_combo(cmb, COMBOX(q)+8+offx, COMBOY(q)+8+offy, darkscr_bmp);
4300 604619 }
4301 137432944 }
4302 780869 }
4303 272141 }
4304
4305 272141 void calc_darkroom_ffcs(mapscr* scr, int offx, int offy)
4306 {
4307 272141 word c = scr->numFFC();
4308
2/2
✓ Branch 0 taken 537406 times.
✓ Branch 1 taken 272141 times.
809547 for(int q = 0; q < c; ++q)
4309 {
4310 537406 newcombo const& cmb = combobuf[scr->ffcs[q].data];
4311
2/2
✓ Branch 0 taken 522598 times.
✓ Branch 1 taken 14808 times.
537406 if(cmb.type == cTORCH)
4312 {
4313 14808 int cx = scr->ffcs[q].x.getInt()+(scr->ffEffectWidth(q)/2)+offx;
4314 14808 int cy = (scr->ffcs[q].y.getInt())+(scr->ffEffectHeight(q)/2)+offy;
4315 14808 do_torch_combo(cmb, cx, cy, darkscr_bmp);
4316 14808 }
4317 537406 }
4318 272141 }
4319
4320 struct nearby_screen_t
4321 {
4322 int screen;
4323 int offx;
4324 int offy;
4325 screen_handles_t screen_handles;
4326 };
4327 typedef std::vector<nearby_screen_t> nearby_screens_t;
4328
4329 15426882 static nearby_screens_t get_nearby_screens_non_scrolling_region()
4330 {
4331 15426882 nearby_screens_t nearby_screens;
4332
4333 15426882 mapscr* base_scr = origin_scr;
4334
1/2
✓ Branch 0 taken 15426882 times.
✗ Branch 1 not taken.
15426882 auto& nearby_screen = nearby_screens.emplace_back();
4335 15426882 nearby_screen.screen = cur_screen;
4336
1/2
✓ Branch 0 taken 15426882 times.
✗ Branch 1 not taken.
15426882 nearby_screen.screen_handles = create_screen_handles(base_scr);
4337
4338 15426882 return nearby_screens;
4339
1/2
✓ Branch 0 taken 15426882 times.
✗ Branch 1 not taken.
15426882 }
4340
4341 48296 static nearby_screens_t get_nearby_screens_scrolling_region()
4342 {
4343 48296 nearby_screens_t nearby_screens;
4344
4345
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_x0 = viewport.left() / 256;
4346
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_x1 = (viewport.right() - 1) / 256;
4347
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_y0 = viewport.top() / 176;
4348
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_y1 = (viewport.bottom() - 1) / 176;
4349
4350
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_x0 = std::clamp(screens_x0, 0, 15);
4351
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_x1 = std::clamp(screens_x1, 0, 15);
4352
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_y0 = std::clamp(screens_y0, 0, 8);
4353
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_y1 = std::clamp(screens_y1, 0, 8);
4354
4355
2/2
✓ Branch 0 taken 48296 times.
✓ Branch 1 taken 79928 times.
128224 for (int x = screens_x0; x <= screens_x1; x++)
4356 {
4357
2/2
✓ Branch 0 taken 169672 times.
✓ Branch 1 taken 79928 times.
249600 for (int y = screens_y0; y <= screens_y1; y++)
4358 {
4359 169672 int screen = cur_screen + x + y*16;
4360
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 if (!is_in_current_region(screen)) continue;
4361
4362
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 mapscr* base_scr = get_scr(screen);
4363
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 if (!base_scr->is_valid()) continue;
4364
4365
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
4366
4367
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 auto& nearby_screen = nearby_screens.emplace_back();
4368 169672 nearby_screen.screen = screen;
4369 169672 nearby_screen.offx = offx;
4370 169672 nearby_screen.offy = offy;
4371
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 nearby_screen.screen_handles = create_screen_handles(base_scr);
4372 169672 }
4373 79928 }
4374
4375 48296 return nearby_screens;
4376
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 }
4377
4378 3658 static nearby_screens_t get_nearby_screens_smooth_maze()
4379 {
4380 3658 nearby_screens_t nearby_screens;
4381
4382
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_x0 = viewport.left() / 256;
4383
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_x1 = (viewport.right() - 1) / 256;
4384
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_y0 = viewport.top() / 176;
4385
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_y1 = (viewport.bottom() - 1) / 176;
4386
4387
2/4
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
3658 if (viewport.left() < 0) screens_x0--;
4388
2/4
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
3658 if (viewport.top() < 0) screens_y0--;
4389
4390
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 7308 times.
10966 for (int x = screens_x0; x <= screens_x1; x++)
4391 {
4392
2/2
✓ Branch 0 taken 18600 times.
✓ Branch 1 taken 7308 times.
25908 for (int y = screens_y0; y <= screens_y1; y++)
4393 {
4394 18600 int screen = -1;
4395 mapscr* base_scr;
4396 int offx, offy;
4397
4398 18600 mapscr* maze_scr = maze_state.scr;
4399 18600 int maze_screen = maze_scr->screen;
4400
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 int maze_screen_x = get_region_relative_dx(maze_screen);
4401
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 int maze_screen_y = get_region_relative_dy(maze_screen);
4402 18600 int maze_screen_dx = x - maze_screen_x;
4403 18600 int maze_screen_dy = y - maze_screen_y;
4404 18600 int exitdir = maze_scr->exitdir;
4405
4406 bool should_draw_maze_screen;
4407
2/2
✓ Branch 0 taken 9052 times.
✓ Branch 1 taken 9548 times.
18600 if (maze_state.lost)
4408 {
4409 9548 should_draw_maze_screen = true;
4410 9548 }
4411 else
4412 {
4413 9052 should_draw_maze_screen = true;
4414
4/6
✓ Branch 0 taken 9052 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6844 times.
✓ Branch 3 taken 2208 times.
✓ Branch 4 taken 6844 times.
✗ Branch 5 not taken.
9052 should_draw_maze_screen &= XY_DELTA_TO_DIR(maze_screen_dx, 0) != exitdir && XY_DELTA_TO_DIR(0, maze_screen_dy) != exitdir;
4415
2/2
✓ Branch 0 taken 3850 times.
✓ Branch 1 taken 5202 times.
9052 if (maze_state.enter_dir != dir_invalid)
4416
4/6
✓ Branch 0 taken 3850 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3304 times.
✓ Branch 3 taken 546 times.
✓ Branch 4 taken 3304 times.
✗ Branch 5 not taken.
3850 should_draw_maze_screen &= XY_DELTA_TO_DIR(maze_screen_dx, 0) != maze_state.enter_dir && XY_DELTA_TO_DIR(0, maze_screen_dy) != maze_state.enter_dir;
4417 }
4418
4419
2/2
✓ Branch 0 taken 16048 times.
✓ Branch 1 taken 2552 times.
18600 if (should_draw_maze_screen)
4420 {
4421 16048 screen = maze_state.scr->screen;
4422 16048 base_scr = maze_state.scr;
4423
1/2
✓ Branch 0 taken 16048 times.
✗ Branch 1 not taken.
16048 std::tie(offx, offy) = translate_screen_coordinates_to_world(cur_screen + x + y*16);
4424 16048 }
4425
4426
2/2
✓ Branch 0 taken 16048 times.
✓ Branch 1 taken 2552 times.
18600 if (screen == -1)
4427 {
4428 2552 screen = cur_screen + x + y*16;
4429
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 if (!is_in_current_region(screen)) continue;
4430
4431
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 base_scr = get_scr(screen);
4432
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 if (!base_scr->is_valid()) continue;
4433
4434
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 std::tie(offx, offy) = translate_screen_coordinates_to_world(screen);
4435 2552 }
4436
4437
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 auto& nearby_screen = nearby_screens.emplace_back();
4438 18600 nearby_screen.screen = screen;
4439 18600 nearby_screen.offx = offx;
4440 18600 nearby_screen.offy = offy;
4441
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 nearby_screen.screen_handles = create_screen_handles(base_scr);
4442 18600 }
4443 7308 }
4444
4445 3658 return nearby_screens;
4446
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 }
4447
4448 15478836 static nearby_screens_t get_nearby_screens()
4449 {
4450
4/4
✓ Branch 0 taken 9214 times.
✓ Branch 1 taken 15469622 times.
✓ Branch 2 taken 3658 times.
✓ Branch 3 taken 5556 times.
15478836 if (maze_state.active && maze_state.loopy)
4451 3658 return get_nearby_screens_smooth_maze();
4452
4453
2/2
✓ Branch 0 taken 48296 times.
✓ Branch 1 taken 15426882 times.
15475178 if (is_in_scrolling_region())
4454 48296 return get_nearby_screens_scrolling_region();
4455
4456 15426882 return get_nearby_screens_non_scrolling_region();
4457 15478836 }
4458
4459 201241099 static void for_every_nearby_screen(const nearby_screens_t& nearby_screens, const std::function <void (screen_handles_t, int, int, int)>& fn)
4460 {
4461
2/2
✓ Branch 0 taken 203025701 times.
✓ Branch 1 taken 201241099 times.
404266800 for (auto& nearby_screen : nearby_screens)
4462 203025701 fn(nearby_screen.screen_handles, nearby_screen.screen, nearby_screen.offx, nearby_screen.offy);
4463 201241099 }
4464
4465 123830688 static void draw_msgstr(byte layer, BITMAP* dest = nullptr)
4466 {
4467
2/2
✓ Branch 0 taken 15478836 times.
✓ Branch 1 taken 108351852 times.
123830688 if(layer != msgstr_layer) return;
4468
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 if(!dest) dest = framebuf;
4469
4470
2/2
✓ Branch 0 taken 677769 times.
✓ Branch 1 taken 14801067 times.
15478836 if(!(msg_bg_display_buf->clip))
4471 {
4472 677769 blit_msgstr_bg(dest,0,0,0,playing_field_offset,256,176);
4473 677769 }
4474
4475
2/2
✓ Branch 0 taken 677769 times.
✓ Branch 1 taken 14801067 times.
15478836 if(!(msg_portrait_display_buf->clip))
4476 {
4477 677769 blit_msgstr_prt(dest,0,0,0,playing_field_offset,256,176);
4478 677769 }
4479
4480
2/2
✓ Branch 0 taken 691176 times.
✓ Branch 1 taken 14787660 times.
15478836 if(!(msg_txt_display_buf->clip))
4481 {
4482 691176 blit_msgstr_fg(dest,0,0,0,playing_field_offset,256,176);
4483 691176 }
4484 123830688 }
4485
4486 static void putscrdoors(const nearby_screens_t& nearby_screens, BITMAP *dest, int32_t x, int32_t y);
4487
4488 61915344 static void set_draw_screen_clip(BITMAP* bmp)
4489 {
4490 61915344 set_clip_rect(bmp, draw_screen_clip_rect_x1, draw_screen_clip_rect_y1, draw_screen_clip_rect_x2, draw_screen_clip_rect_y2);
4491 61915344 }
4492
4493 45935612 void draw_screen(bool showhero, bool runGeneric)
4494 {
4495 45935612 clear_info_bmp();
4496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45935612 times.
45935612 if((GameFlags & (GAMEFLAG_SCRIPTMENU_ACTIVE|GAMEFLAG_F6SCRIPT_ACTIVE))!=0)
4497 {
4498 FFCore.doScriptMenuDraws();
4499 return;
4500 }
4501
4502
2/2
✓ Branch 0 taken 31055386 times.
✓ Branch 1 taken 14880226 times.
45935612 if(runGeneric) FFCore.runGenericPassiveEngine(SCR_TIMING_PRE_DRAW);
4503
4504 45935612 clear_bitmap(framebuf);
4505 45935612 clear_clip_rect(framebuf);
4506
4507 45935612 int32_t cmby2=0;
4508
4509 // Draw some background layers
4510 45935612 clear_bitmap(scrollbuf);
4511
4512 45935612 auto nearby_screens = get_nearby_screens();
4513
4514 // Handle layer 2/3 possibly being background layers.
4515
1/2
✓ Branch 0 taken 45935612 times.
✗ Branch 1 not taken.
61550766 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4516 15615154 mapscr* base_scr = screen_handles[0].base_scr;
4517
2/2
✓ Branch 0 taken 15487872 times.
✓ Branch 1 taken 127282 times.
15615154 if (XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4518 127282 do_layer(scrollbuf, 0, screen_handles[2], offx, offy);
4519 15615154 });
4520
4521
2/2
✓ Branch 0 taken 127282 times.
✓ Branch 1 taken 45808330 times.
45935612 if (XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4522 {
4523
1/2
✓ Branch 0 taken 127282 times.
✗ Branch 1 not taken.
127282 do_layer_primitives(scrollbuf, 2);
4524
1/2
✓ Branch 0 taken 127282 times.
✗ Branch 1 not taken.
127282 particles.draw(scrollbuf, true, 2);
4525 127282 }
4526
2/2
✓ Branch 0 taken 15478836 times.
✓ Branch 1 taken 30456776 times.
45935612 _do_current_ffc_layer(scrollbuf, -2);
4527
2/2
✓ Branch 0 taken 127282 times.
✓ Branch 1 taken 15351554 times.
15478836 if (XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4528
1/2
✓ Branch 0 taken 127282 times.
✗ Branch 1 not taken.
127282 draw_msgstr(2, scrollbuf);
4529
4530
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
31093990 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4531 15615154 mapscr* base_scr = screen_handles[0].base_scr;
4532
2/2
✓ Branch 0 taken 15522494 times.
✓ Branch 1 taken 92660 times.
15615154 if (XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4533 92660 do_layer(scrollbuf, 0, screen_handles[3], offx, offy);
4534 15615154 });
4535
4536
2/2
✓ Branch 0 taken 92660 times.
✓ Branch 1 taken 15386176 times.
15478836 if (XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4537 {
4538
1/2
✓ Branch 0 taken 92660 times.
✗ Branch 1 not taken.
92660 do_layer_primitives(scrollbuf, 3);
4539
1/2
✓ Branch 0 taken 92660 times.
✗ Branch 1 not taken.
92660 particles.draw(scrollbuf, true, 3);
4540 92660 }
4541
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 _do_current_ffc_layer(scrollbuf, -3);
4542
2/2
✓ Branch 0 taken 92660 times.
✓ Branch 1 taken 15386176 times.
15478836 if (XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4543
1/2
✓ Branch 0 taken 92660 times.
✗ Branch 1 not taken.
92660 draw_msgstr(3, scrollbuf);
4544
4545 // Draw the main combo screens ("layer 0").
4546
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
31093990 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4547 15615154 mapscr* base_scr = screen_handles[0].base_scr;
4548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15615154 times.
15615154 if (lenscheck(base_scr, 0))
4549 {
4550 15615154 putscr(base_scr, scrollbuf, offx, offy + playing_field_offset);
4551 15615154 }
4552 15615154 });
4553
4554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15478836 times.
15478836 if (lenscheck(hero_scr, 0))
4555 {
4556
2/2
✓ Branch 0 taken 471311 times.
✓ Branch 1 taken 15007525 times.
15478836 if(!get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4557
3/4
✓ Branch 0 taken 471311 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4136 times.
✓ Branch 3 taken 467175 times.
475447 if(mblock2.draw(scrollbuf,0))
4558
1/2
✓ Branch 0 taken 4136 times.
✗ Branch 1 not taken.
4136 do_primitives(scrollbuf, SPLAYER_MOVINGBLOCK);
4559 15478836 }
4560
4561 // Lens hints, then primitives, then particles.
4562
6/10
✓ Branch 0 taken 15468807 times.
✓ Branch 1 taken 10029 times.
✓ Branch 2 taken 15468807 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15468807 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 5876 times.
✓ Branch 9 taken 4153 times.
15478836 if((lensclk || (get_debug() && zc_getkey(KEY_L))) && !get_qr(qr_OLDLENSORDER))
4563 {
4564
1/2
✓ Branch 0 taken 5876 times.
✗ Branch 1 not taken.
5876 draw_lens_under(scrollbuf, false);
4565
1/2
✓ Branch 0 taken 5876 times.
✗ Branch 1 not taken.
5876 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_1);
4566 5876 }
4567
4568
2/4
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15478836 times.
✗ Branch 3 not taken.
15478836 if(show_layers[0] && lenscheck(hero_scr,0))
4569
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 do_primitives(scrollbuf, 0);
4570
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 particles.draw(scrollbuf, true, 0);
4571
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 _do_current_ffc_layer(scrollbuf, 0);
4572
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 draw_msgstr(0, scrollbuf);
4573
4574
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 set_draw_screen_clip(scrollbuf);
4575
4576
2/2
✓ Branch 0 taken 15135577 times.
✓ Branch 1 taken 343259 times.
15478836 if(!(get_qr(qr_LAYER12UNDERCAVE)))
4577 {
4578
4/4
✓ Branch 0 taken 15133711 times.
✓ Branch 1 taken 1866 times.
✓ Branch 2 taken 53248 times.
✓ Branch 3 taken 15045711 times.
30234536 if(showhero &&
4579
4/6
✓ Branch 0 taken 15133711 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15098959 times.
✓ Branch 3 taken 34752 times.
✓ Branch 4 taken 15098959 times.
✗ Branch 5 not taken.
15133711 ((Hero.getAction()==climbcovertop)||(Hero.getAction()==climbcoverbottom)))
4580 {
4581
3/4
✓ Branch 0 taken 88000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53248 times.
✓ Branch 3 taken 34752 times.
88000 if(Hero.getAction()==climbcovertop)
4582 {
4583 34752 cmby2=16;
4584 34752 }
4585
2/4
✓ Branch 0 taken 53248 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53248 times.
53248 else if(Hero.getAction()==climbcoverbottom)
4586 {
4587 53248 cmby2=-16;
4588 53248 }
4589
4590
1/2
✓ Branch 0 taken 88000 times.
✗ Branch 1 not taken.
88000 decorations.draw2(scrollbuf,true);
4591
1/2
✓ Branch 0 taken 88000 times.
✗ Branch 1 not taken.
88000 Hero.draw(scrollbuf);
4592
1/2
✓ Branch 0 taken 88000 times.
✗ Branch 1 not taken.
88000 decorations.draw(scrollbuf,true);
4593
2/4
✓ Branch 0 taken 88000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88000 times.
✗ Branch 3 not taken.
88000 int32_t ccx = (int32_t)Hero.getClimbCoverX();
4594
2/4
✓ Branch 0 taken 88000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88000 times.
✗ Branch 3 not taken.
88000 int32_t ccy = (int32_t)Hero.getClimbCoverY();
4595
4596
3/6
✓ Branch 0 taken 88000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88000 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88000 times.
✗ Branch 5 not taken.
88000 overcombo(scrollbuf,ccx-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy+cmby2),MAPCSET(ccx,ccy+cmby2));
4597
3/6
✓ Branch 0 taken 88000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88000 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88000 times.
✗ Branch 5 not taken.
88000 putcombo(scrollbuf,ccx-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy),MAPCSET(ccx,ccy));
4598
4599
4/6
✓ Branch 0 taken 88000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88000 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15104 times.
✓ Branch 5 taken 72896 times.
88000 if(int32_t(Hero.getX())&15)
4600 {
4601
3/6
✓ Branch 0 taken 15104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15104 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15104 times.
✗ Branch 5 not taken.
15104 overcombo(scrollbuf,ccx+16-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy+cmby2),MAPCSET(ccx+16,ccy+cmby2));
4602
3/6
✓ Branch 0 taken 15104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15104 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15104 times.
✗ Branch 5 not taken.
15104 putcombo(scrollbuf,ccx+16-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy),MAPCSET(ccx+16,ccy));
4603 15104 }
4604 88000 }
4605 15135577 }
4606
4607
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
31093990 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4608 15615154 do_layer(scrollbuf, 0, screen_handles[1], offx, offy); // LAYER 1
4609 15615154 });
4610
4611
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 do_layer_primitives(scrollbuf, 1);
4612
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 particles.draw(scrollbuf, true, 1);
4613
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 _do_current_ffc_layer(scrollbuf, 1);
4614
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 draw_msgstr(1, scrollbuf);
4615
4616 // Handle layer 2 NOT being used as background layers.
4617
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
31093990 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4618 15615154 mapscr* base_scr = screen_handles[0].base_scr;
4619
2/2
✓ Branch 0 taken 127282 times.
✓ Branch 1 taken 15487872 times.
15615154 if (!XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4620 15487872 do_layer(scrollbuf, 0, screen_handles[2], offx, offy);
4621 15615154 });
4622
4623
2/2
✓ Branch 0 taken 15351554 times.
✓ Branch 1 taken 127282 times.
15478836 if(!XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4624 {
4625
1/2
✓ Branch 0 taken 15351554 times.
✗ Branch 1 not taken.
15351554 do_layer_primitives(scrollbuf, 2);
4626
1/2
✓ Branch 0 taken 15351554 times.
✗ Branch 1 not taken.
15351554 particles.draw(scrollbuf, true, 2);
4627 15351554 }
4628
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 _do_current_ffc_layer(scrollbuf, 2);
4629
2/2
✓ Branch 0 taken 15351554 times.
✓ Branch 1 taken 127282 times.
15478836 if(!XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4630
1/2
✓ Branch 0 taken 15351554 times.
✗ Branch 1 not taken.
15351554 draw_msgstr(2, scrollbuf);
4631
4632
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 do_primitives(scrollbuf, SPLAYER_FFC_DRAW);
4633
4634
2/2
✓ Branch 0 taken 343259 times.
✓ Branch 1 taken 15135577 times.
15478836 if(get_qr(qr_LAYER12UNDERCAVE))
4635 {
4636
2/4
✓ Branch 0 taken 343259 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 343259 times.
686518 if(showhero &&
4637
3/6
✓ Branch 0 taken 343259 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 343259 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 343259 times.
✗ Branch 5 not taken.
343259 ((Hero.getAction()==climbcovertop)||(Hero.getAction()==climbcoverbottom)))
4638 {
4639 if(Hero.getAction()==climbcovertop)
4640 {
4641 cmby2=16;
4642 }
4643 else if(Hero.getAction()==climbcoverbottom)
4644 {
4645 cmby2=-16;
4646 }
4647
4648 decorations.draw2(scrollbuf,true);
4649 Hero.draw(scrollbuf);
4650 decorations.draw(scrollbuf,true);
4651 int32_t ccx = (int32_t)(Hero.getClimbCoverX());
4652 int32_t ccy = (int32_t)(Hero.getClimbCoverY());
4653
4654 overcombo(scrollbuf,ccx-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy+cmby2),MAPCSET(ccx,ccy+cmby2));
4655 putcombo(scrollbuf,ccx-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy),MAPCSET(ccx,ccy));
4656
4657 if(int32_t(Hero.getX())&15)
4658 {
4659 overcombo(scrollbuf,ccx+16-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy+cmby2),MAPCSET(ccx+16,ccy+cmby2));
4660 putcombo(scrollbuf,ccx+16-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy),MAPCSET(ccx+16,ccy));
4661 }
4662 }
4663 343259 }
4664
4665
2/2
✓ Branch 0 taken 471311 times.
✓ Branch 1 taken 15007525 times.
15478836 if (get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4666 {
4667
1/2
✓ Branch 0 taken 15007525 times.
✗ Branch 1 not taken.
30151368 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4668 15143843 do_layer(scrollbuf, -2, screen_handles[0], offx, offy); // push blocks!
4669
2/2
✓ Branch 0 taken 14413287 times.
✓ Branch 1 taken 730556 times.
15143843 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
4670 {
4671 730556 do_layer(scrollbuf, -2, screen_handles[1], offx, offy); // push blocks!
4672 730556 do_layer(scrollbuf, -2, screen_handles[2], offx, offy); // push blocks!
4673 730556 }
4674 15143843 });
4675
4676
1/2
✓ Branch 0 taken 15007525 times.
✗ Branch 1 not taken.
15007525 do_primitives(scrollbuf, SPLAYER_PUSHBLOCK);
4677 15007525 }
4678
4679 // Show walkflags cheat
4680
2/4
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15478836 times.
15478836 if (show_walkflags || show_effectflags)
4681 {
4682 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4683 do_walkflags(screen_handles, offx, offy);
4684 do_effectflags(screen_handles[0].base_scr, offx, offy);
4685 });
4686
4687 do_walkflags(0, 0);
4688 }
4689
4690
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 putscrdoors(nearby_screens, scrollbuf, 0, playing_field_offset);
4691
4692 // Lens hints, doors etc.
4693
4/8
✓ Branch 0 taken 15468807 times.
✓ Branch 1 taken 10029 times.
✓ Branch 2 taken 15468807 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15468807 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
15478836 if(lensclk || (get_debug() && zc_getkey(KEY_L)))
4694 {
4695
2/2
✓ Branch 0 taken 4153 times.
✓ Branch 1 taken 5876 times.
10029 if(get_qr(qr_OLDLENSORDER))
4696 {
4697
1/2
✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
4153 draw_lens_under(scrollbuf, false);
4698
1/2
✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
4153 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_1);
4699 4153 }
4700
4701
1/2
✓ Branch 0 taken 10029 times.
✗ Branch 1 not taken.
10029 draw_lens_under(scrollbuf, true);
4702
1/2
✓ Branch 0 taken 10029 times.
✗ Branch 1 not taken.
10029 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_2);
4703 10029 }
4704
4705 // Blit those layers onto framebuf
4706
4707
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 set_draw_screen_clip(framebuf);
4708
4709
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 blit(scrollbuf, framebuf, 0, 0, 0, 0, 256, 232);
4710
4711 // After this point, scrollbuf is no longer drawn to - so things like dosubscr have access to a "partially rendered" frame.
4712 // I think only used for COOLSCROLL==0? Seems like a silly feature...
4713
4714 // Draw the subscreen, without clipping
4715
2/2
✓ Branch 0 taken 9250859 times.
✓ Branch 1 taken 6227977 times.
15478836 if(!get_qr(qr_SUBSCREENOVERSPRITES))
4716 {
4717 9250859 bool dotime = false;
4718
4/6
✓ Branch 0 taken 9250859 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3412328 times.
✓ Branch 3 taken 5838531 times.
✓ Branch 4 taken 3412328 times.
✗ Branch 5 not taken.
9250859 if (replay_version_check(22)) dotime = game->should_show_time();
4719
1/2
✓ Branch 0 taken 9250859 times.
✗ Branch 1 not taken.
9250859 put_passive_subscr(framebuf, 0, 0, dotime, sspUP);
4720 9250859 }
4721
4722 // Draw some sprites onto framebuf
4723
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 set_clip_rect(framebuf,0,0,256,232);
4724
4725
2/2
✓ Branch 0 taken 99044 times.
✓ Branch 1 taken 15379792 times.
15478836 if(!(pricesdisplaybuf->clip))
4726 {
4727
1/2
✓ Branch 0 taken 99044 times.
✗ Branch 1 not taken.
99044 masked_blit(pricesdisplaybuf,framebuf,0,0,0,playing_field_offset,256,176);
4728 99044 }
4729
4730
5/6
✓ Branch 0 taken 15433210 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15426882 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15478836 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
4731 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
4732
4733
8/10
✓ Branch 0 taken 15476970 times.
✓ Branch 1 taken 1866 times.
✓ Branch 2 taken 15476970 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15442218 times.
✓ Branch 5 taken 34752 times.
✓ Branch 6 taken 15442218 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15388970 times.
✓ Branch 9 taken 53248 times.
15478836 if(showhero && ((Hero.getAction()!=climbcovertop)&&(Hero.getAction()!=climbcoverbottom)))
4734 {
4735
1/2
✓ Branch 0 taken 15388970 times.
✗ Branch 1 not taken.
15388970 Hero.draw_under(framebuf);
4736
4737
3/4
✓ Branch 0 taken 15388970 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 141385 times.
✓ Branch 3 taken 15247585 times.
15388970 if(Hero.isSwimming())
4738 {
4739
1/2
✓ Branch 0 taken 141385 times.
✗ Branch 1 not taken.
141385 decorations.draw2(framebuf,true);
4740
1/2
✓ Branch 0 taken 141385 times.
✗ Branch 1 not taken.
141385 Hero.draw(framebuf);
4741
1/2
✓ Branch 0 taken 141385 times.
✗ Branch 1 not taken.
141385 decorations.draw(framebuf,true);
4742 141385 }
4743 15388970 }
4744
4745
2/2
✓ Branch 0 taken 25967 times.
✓ Branch 1 taken 15452869 times.
15478836 if(drawguys)
4746 {
4747
4/4
✓ Branch 0 taken 1982149 times.
✓ Branch 1 taken 13470720 times.
✓ Branch 2 taken 990826 times.
✓ Branch 3 taken 991323 times.
15452869 if(get_qr(qr_NOFLICKER) || (frame&1))
4748 {
4749 // Just clips sprites if in a repeating, smooth maze.
4750
2/2
✓ Branch 0 taken 14452332 times.
✓ Branch 1 taken 9214 times.
14461546 bool do_clip = maze_state.active && maze_state.loopy;
4751
4752
3/4
✓ Branch 0 taken 23554187 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9092641 times.
✓ Branch 3 taken 14461546 times.
23554187 for(int32_t i=0; i<Ewpns.Count(); i++)
4753 {
4754
3/4
✓ Branch 0 taken 9092641 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 197943 times.
✓ Branch 3 taken 8894698 times.
9092641 if(((weapon *)Ewpns.spr(i))->behind)
4755
2/4
✓ Branch 0 taken 197943 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 197943 times.
✗ Branch 3 not taken.
197943 Ewpns.spr(i)->draw(framebuf);
4756 9092641 }
4757
1/2
✓ Branch 0 taken 14461546 times.
✗ Branch 1 not taken.
14461546 do_primitives(framebuf, SPLAYER_EWEAP_BEHIND_DRAW);
4758
4759
3/4
✓ Branch 0 taken 19068598 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4607052 times.
✓ Branch 3 taken 14461546 times.
19068598 for(int32_t i=0; i<Lwpns.Count(); i++)
4760 {
4761
3/4
✓ Branch 0 taken 4607052 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3205 times.
✓ Branch 3 taken 4603847 times.
4607052 if(((weapon *)Lwpns.spr(i))->behind)
4762
2/4
✓ Branch 0 taken 3205 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3205 times.
✗ Branch 3 not taken.
3205 Lwpns.spr(i)->draw(framebuf);
4763 4607052 }
4764
1/2
✓ Branch 0 taken 14461546 times.
✗ Branch 1 not taken.
14461546 do_primitives(framebuf, SPLAYER_LWEAP_BEHIND_DRAW);
4765
4766
6/6
✓ Branch 0 taken 9724945 times.
✓ Branch 1 taken 4736601 times.
✓ Branch 2 taken 1283319 times.
✓ Branch 3 taken 8441626 times.
✓ Branch 4 taken 641525 times.
✓ Branch 5 taken 641794 times.
14461546 if(get_qr(qr_SHADOWS)&&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
4767 {
4768
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 9079493 times.
9083151 if (do_clip)
4769
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 guys.drawshadow_smooth_maze(framebuf,get_qr(qr_TRANSSHADOWS)!=0);
4770 else
4771
1/2
✓ Branch 0 taken 9079493 times.
✗ Branch 1 not taken.
9079493 guys.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0,true);
4772 9083151 }
4773
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14457888 times.
14461546 if (do_clip)
4774
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 guys.draw_smooth_maze(framebuf);
4775 else
4776
1/2
✓ Branch 0 taken 14457888 times.
✗ Branch 1 not taken.
14457888 guys.draw(framebuf,true);
4777
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14457888 times.
14461546 if (do_clip)
4778 {
4779 3658 int maze_screen = maze_state.scr->screen;
4780
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 auto [sx, sy] = translate_screen_coordinates_to_world(maze_screen);
4781
5/10
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3658 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3658 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3658 times.
✗ Branch 9 not taken.
18290 set_clip_rect(framebuf, sx - viewport.x, sy - viewport.y, sx + 256 - viewport.x, sy + 176 - viewport.y);
4782 3658 }
4783
1/2
✓ Branch 0 taken 14461546 times.
✗ Branch 1 not taken.
14461546 do_primitives(framebuf, SPLAYER_NPC_DRAW);
4784
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14457888 times.
14461546 if (do_clip)
4785
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 clear_clip_rect(framebuf);
4786
4787
1/2
✓ Branch 0 taken 14461546 times.
✗ Branch 1 not taken.
14461546 chainlinks.draw(framebuf,true);
4788
1/2
✓ Branch 0 taken 14461546 times.
✗ Branch 1 not taken.
14461546 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
4789 //Lwpns.draw(framebuf,true);
4790
4791
3/4
✓ Branch 0 taken 23554187 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9092641 times.
✓ Branch 3 taken 14461546 times.
23554187 for(int32_t i=0; i<Ewpns.Count(); i++)
4792 {
4793
3/4
✓ Branch 0 taken 9092641 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8894698 times.
✓ Branch 3 taken 197943 times.
9092641 if(!((weapon *)Ewpns.spr(i))->behind)
4794
2/4
✓ Branch 0 taken 8894698 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8894698 times.
✗ Branch 3 not taken.
8894698 Ewpns.spr(i)->draw(framebuf);
4795 9092641 }
4796
1/2
✓ Branch 0 taken 14461546 times.
✗ Branch 1 not taken.
14461546 do_primitives(framebuf, SPLAYER_EWEAP_FRONT_DRAW);
4797
4798
3/4
✓ Branch 0 taken 19068598 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4607052 times.
✓ Branch 3 taken 14461546 times.
19068598 for(int32_t i=0; i<Lwpns.Count(); i++)
4799 {
4800
3/4
✓ Branch 0 taken 4607052 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4603847 times.
✓ Branch 3 taken 3205 times.
4607052 if(!((weapon *)Lwpns.spr(i))->behind)
4801
2/4
✓ Branch 0 taken 4603847 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4603847 times.
✗ Branch 3 not taken.
4603847 Lwpns.spr(i)->draw(framebuf);
4802 4607052 }
4803
1/2
✓ Branch 0 taken 14461546 times.
✗ Branch 1 not taken.
14461546 do_primitives(framebuf, SPLAYER_LWEAP_FRONT_DRAW);
4804
4805
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14457888 times.
14461546 if (do_clip)
4806
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 items.draw_smooth_maze(framebuf);
4807 else
4808
1/2
✓ Branch 0 taken 14457888 times.
✗ Branch 1 not taken.
14457888 items.draw(framebuf,true);
4809
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14457888 times.
14461546 if (do_clip)
4810 {
4811 3658 int maze_screen = maze_state.scr->screen;
4812
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 auto [sx, sy] = translate_screen_coordinates_to_world(maze_screen);
4813
5/10
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3658 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3658 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3658 times.
✗ Branch 9 not taken.
18290 set_clip_rect(framebuf, sx - viewport.x, sy - viewport.y, sx + 256 - viewport.x, sy + 176 - viewport.y);
4814 3658 }
4815
1/2
✓ Branch 0 taken 14461546 times.
✗ Branch 1 not taken.
14461546 do_primitives(framebuf, SPLAYER_ITEMSPRITE_DRAW);
4816
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14457888 times.
14461546 if (do_clip)
4817
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 clear_clip_rect(framebuf);
4818 14461546 }
4819 else
4820 {
4821
3/4
✓ Branch 0 taken 1496695 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 505372 times.
✓ Branch 3 taken 991323 times.
1496695 for(int32_t i=0; i<Ewpns.Count(); i++)
4822 {
4823
3/4
✓ Branch 0 taken 505372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8645 times.
✓ Branch 3 taken 496727 times.
505372 if(((weapon *)Ewpns.spr(i))->behind)
4824
2/4
✓ Branch 0 taken 8645 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8645 times.
✗ Branch 3 not taken.
8645 Ewpns.spr(i)->draw(framebuf);
4825 505372 }
4826
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_EWEAP_BEHIND_DRAW);
4827
4828
3/4
✓ Branch 0 taken 1222321 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230998 times.
✓ Branch 3 taken 991323 times.
1222321 for(int32_t i=0; i<Lwpns.Count(); i++)
4829 {
4830
2/4
✓ Branch 0 taken 230998 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 230998 times.
230998 if(((weapon *)Lwpns.spr(i))->behind)
4831 Lwpns.spr(i)->draw(framebuf);
4832 230998 }
4833
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_LWEAP_BEHIND_DRAW);
4834
4835
3/4
✓ Branch 0 taken 228620 times.
✓ Branch 1 taken 762703 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 228620 times.
991323 if(get_qr(qr_SHADOWS)&&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
4836 {
4837
1/2
✓ Branch 0 taken 228620 times.
✗ Branch 1 not taken.
228620 guys.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0,true);
4838 228620 }
4839
4840
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 items.draw(framebuf,false);
4841
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_ITEMSPRITE_DRAW);
4842
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 chainlinks.draw(framebuf,false);
4843
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
4844 //Lwpns.draw(framebuf,false);
4845
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 guys.draw(framebuf,false);
4846
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_NPC_DRAW);
4847
4848
3/4
✓ Branch 0 taken 1496695 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 505372 times.
✓ Branch 3 taken 991323 times.
1496695 for(int32_t i=0; i<Ewpns.Count(); i++)
4849 {
4850
3/4
✓ Branch 0 taken 505372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 496727 times.
✓ Branch 3 taken 8645 times.
505372 if(!((weapon *)Ewpns.spr(i))->behind)
4851 {
4852
2/4
✓ Branch 0 taken 496727 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 496727 times.
✗ Branch 3 not taken.
496727 Ewpns.spr(i)->draw(framebuf);
4853 496727 }
4854 505372 }
4855
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_EWEAP_FRONT_DRAW);
4856
4857
3/4
✓ Branch 0 taken 1222321 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230998 times.
✓ Branch 3 taken 991323 times.
1222321 for(int32_t i=0; i<Lwpns.Count(); i++)
4858 {
4859
2/4
✓ Branch 0 taken 230998 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230998 times.
✗ Branch 3 not taken.
230998 if(!((weapon *)Lwpns.spr(i))->behind)
4860 {
4861
2/4
✓ Branch 0 taken 230998 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230998 times.
✗ Branch 3 not taken.
230998 Lwpns.spr(i)->draw(framebuf);
4862 230998 }
4863 230998 }
4864
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_LWEAP_FRONT_DRAW);
4865 }
4866
4867
1/2
✓ Branch 0 taken 15452869 times.
✗ Branch 1 not taken.
15452869 guys.draw2(framebuf,true);
4868 15452869 }
4869
4870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15478836 times.
15478836 if(mirror_portal.destdmap > -1)
4871 mirror_portal.draw(framebuf);
4872
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 portals.draw(framebuf,true);
4873
4874
8/10
✓ Branch 0 taken 15476970 times.
✓ Branch 1 taken 1866 times.
✓ Branch 2 taken 15476970 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15442218 times.
✓ Branch 5 taken 34752 times.
✓ Branch 6 taken 15442218 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15388970 times.
✓ Branch 9 taken 53248 times.
15478836 if(showhero && ((Hero.getAction()!=climbcovertop)&& (Hero.getAction()!=climbcoverbottom)))
4875 {
4876
2/2
✓ Branch 0 taken 14924075 times.
✓ Branch 1 taken 464895 times.
15388970 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4877 {
4878
1/2
✓ Branch 0 taken 14924075 times.
✗ Branch 1 not taken.
14924075 mblock2.draw(framebuf,-1);
4879
1/2
✓ Branch 0 taken 14924075 times.
✗ Branch 1 not taken.
14924075 do_primitives(framebuf, SPLAYER_MOVINGBLOCK);
4880 14924075 }
4881
3/4
✓ Branch 0 taken 15388970 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15247585 times.
✓ Branch 3 taken 141385 times.
15388970 if(!Hero.isSwimming())
4882 {
4883
8/12
✓ Branch 0 taken 15247585 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15247585 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15227703 times.
✓ Branch 5 taken 19882 times.
✓ Branch 6 taken 15227703 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15227703 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1370 times.
✓ Branch 11 taken 15246215 times.
15247585 if((Hero.getZ()>0 || Hero.getFakeZ()>0) &&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
4884 {
4885
2/2
✓ Branch 0 taken 19197 times.
✓ Branch 1 taken 15228388 times.
15247585 Hero.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0);
4886 19197 }
4887
4888
6/8
✓ Branch 0 taken 15247585 times.
✓ Branch 1 taken 15228388 times.
✓ Branch 2 taken 15247585 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15247585 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 15233164 times.
✓ Branch 7 taken 14421 times.
19197 if(Hero.getZ() <= (zfix)zinit.jump_hero_layer_threshold)
4889 {
4890
1/2
✓ Branch 0 taken 15233164 times.
✗ Branch 1 not taken.
15233164 decorations.draw2(framebuf,true);
4891
1/2
✓ Branch 0 taken 15233164 times.
✗ Branch 1 not taken.
15233164 Hero.draw(framebuf);
4892
1/2
✓ Branch 0 taken 15233164 times.
✗ Branch 1 not taken.
15233164 decorations.draw(framebuf,true);
4893 15233164 }
4894 15247585 }
4895 15388970 }
4896
4897
3/4
✓ Branch 0 taken 54645931 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39167095 times.
✓ Branch 3 taken 15478836 times.
54645931 for(int32_t i=0; i<guys.Count(); i++)
4898 {
4899
3/4
✓ Branch 0 taken 39167095 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15856206 times.
✓ Branch 3 taken 23310889 times.
39167095 if(((enemy*)guys.spr(i))->family == eeWALK)
4900 {
4901
3/4
✓ Branch 0 taken 15856206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7247 times.
✓ Branch 3 taken 15848959 times.
15856206 if(((eStalfos*)guys.spr(i))->hashero)
4902 {
4903
2/4
✓ Branch 0 taken 7247 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7247 times.
✗ Branch 3 not taken.
7247 guys.spr(i)->draw(framebuf);
4904 7247 }
4905 15856206 }
4906
4907
3/4
✓ Branch 0 taken 39167095 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 507162 times.
✓ Branch 3 taken 38659933 times.
39167095 if(((enemy*)guys.spr(i))->family == eeWALLM)
4908 {
4909
3/4
✓ Branch 0 taken 507162 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1329 times.
✓ Branch 3 taken 505833 times.
507162 if(((eWallM*)guys.spr(i))->hashero)
4910 {
4911
2/4
✓ Branch 0 taken 1329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1329 times.
✗ Branch 3 not taken.
1329 guys.spr(i)->draw(framebuf);
4912 1329 }
4913 507162 }
4914
4915
11/20
✓ Branch 0 taken 39167095 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 39167095 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39167095 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 39167095 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 39167095 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 39167095 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 39167095 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 39167095 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 39167095 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1294560 times.
✓ Branch 19 taken 37872535 times.
39167095 if(guys.spr(i)->z+guys.spr(i)->fakez > Hero.getZ()+Hero.getFakeZ())
4916 {
4917 //Jumping enemies in front of Hero.
4918
2/4
✓ Branch 0 taken 1294560 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1294560 times.
✗ Branch 3 not taken.
1294560 guys.spr(i)->draw(framebuf);
4919 1294560 }
4920
1/2
✓ Branch 0 taken 39167095 times.
✗ Branch 1 not taken.
39167095 do_primitives(framebuf, SPLAYER_NPC_ABOVEPLAYER_DRAW);
4921 39167095 }
4922
4923 // Draw some layers onto framebuf
4924
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 set_draw_screen_clip(framebuf);
4925
5/6
✓ Branch 0 taken 15433210 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15426882 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15478836 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
4926 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
4927
4928 // Handle layer 3 NOT being used as background layers.
4929
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
31093990 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4930 15615154 mapscr* base_scr = screen_handles[0].base_scr;
4931
2/2
✓ Branch 0 taken 92660 times.
✓ Branch 1 taken 15522494 times.
15615154 if (!XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4932 15522494 do_layer(framebuf, 0, screen_handles[3], offx, offy);
4933 15615154 });
4934
4935
2/2
✓ Branch 0 taken 15386176 times.
✓ Branch 1 taken 92660 times.
15478836 if(!XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4936 {
4937
1/2
✓ Branch 0 taken 15386176 times.
✗ Branch 1 not taken.
15386176 do_layer_primitives(framebuf, 3);
4938
1/2
✓ Branch 0 taken 15386176 times.
✗ Branch 1 not taken.
15386176 particles.draw(framebuf, true, 3);
4939 15386176 }
4940
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 _do_current_ffc_layer(framebuf, 3);
4941
2/2
✓ Branch 0 taken 15386176 times.
✓ Branch 1 taken 92660 times.
15478836 if(!XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4942
1/2
✓ Branch 0 taken 15386176 times.
✗ Branch 1 not taken.
15386176 draw_msgstr(3);
4943
4944
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
31093990 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4945 15615154 do_layer(framebuf, 0, screen_handles[4], offx, offy);
4946 15615154 });
4947
4948
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 do_layer_primitives(framebuf, 4);
4949
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 particles.draw(framebuf, true, 4);
4950
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 _do_current_ffc_layer(framebuf, 4);
4951
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 draw_msgstr(4);
4952
4953
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
31093990 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4954 15615154 do_layer(framebuf, -1, screen_handles[0], offx, offy);
4955
2/2
✓ Branch 0 taken 14334567 times.
✓ Branch 1 taken 1280587 times.
15615154 if (get_qr(qr_OVERHEAD_COMBOS_L1_L2))
4956 {
4957 1280587 do_layer(framebuf, -1, screen_handles[1], offx, offy);
4958 1280587 do_layer(framebuf, -1, screen_handles[2], offx, offy);
4959 1280587 }
4960 15615154 });
4961
4962
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 do_primitives(framebuf, SPLAYER_OVERHEAD_CMB);
4963
4964 // Draw some flying sprites onto framebuf
4965
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 clear_clip_rect(framebuf);
4966
5/6
✓ Branch 0 taken 15433210 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15426882 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15478836 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
4967 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
4968
4969 //Jumping Hero and jumping enemies are drawn on this layer.
4970
5/8
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15478836 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15478836 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 14421 times.
✓ Branch 7 taken 15464415 times.
15478836 if(Hero.getZ() > (zfix)zinit.jump_hero_layer_threshold)
4971 {
4972
1/2
✓ Branch 0 taken 14421 times.
✗ Branch 1 not taken.
14421 decorations.draw2(framebuf,false);
4973
1/2
✓ Branch 0 taken 14421 times.
✗ Branch 1 not taken.
14421 Hero.draw(framebuf);
4974
1/2
✓ Branch 0 taken 14421 times.
✗ Branch 1 not taken.
14421 chainlinks.draw(framebuf,true);
4975
1/2
✓ Branch 0 taken 14421 times.
✗ Branch 1 not taken.
14421 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
4976
4977
3/4
✓ Branch 0 taken 17163 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2742 times.
✓ Branch 3 taken 14421 times.
17163 for(int32_t i=0; i<Lwpns.Count(); i++)
4978 {
4979
9/16
✓ Branch 0 taken 2742 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2742 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2742 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2742 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2742 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2742 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2742 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 239 times.
✓ Branch 15 taken 2503 times.
2742 if(Lwpns.spr(i)->z+Lwpns.spr(i)->fakez > (zfix)zinit.jump_hero_layer_threshold)
4980 {
4981
2/4
✓ Branch 0 taken 239 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 239 times.
✗ Branch 3 not taken.
239 Lwpns.spr(i)->draw(framebuf);
4982 239 }
4983 2742 }
4984
1/2
✓ Branch 0 taken 14421 times.
✗ Branch 1 not taken.
14421 do_primitives(framebuf, SPLAYER_LWEAP_ABOVE_DRAW);
4985
4986
1/2
✓ Branch 0 taken 14421 times.
✗ Branch 1 not taken.
14421 decorations.draw(framebuf,false);
4987 14421 }
4988
4989
5/6
✓ Branch 0 taken 3223873 times.
✓ Branch 1 taken 12254963 times.
✓ Branch 2 taken 44336946 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 32081983 times.
✓ Branch 5 taken 12254963 times.
47560819 if(!get_qr(qr_ENEMIESZAXIS)) for(int32_t i=0; i<guys.Count(); i++)
4990 {
4991
13/22
✓ Branch 0 taken 32081983 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32081983 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 27175885 times.
✓ Branch 5 taken 4906098 times.
✓ Branch 6 taken 27175885 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 27175885 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27175885 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 27175885 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 27175885 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 27175885 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 27175885 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 6568 times.
✓ Branch 21 taken 27169317 times.
32081983 if((isflier(guys.spr(i)->id)) || (guys.spr(i)->z+guys.spr(i)->fakez) > (zfix)zinit.jump_hero_layer_threshold)
4992 {
4993
2/4
✓ Branch 0 taken 4912666 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4912666 times.
✗ Branch 3 not taken.
4912666 guys.spr(i)->draw(framebuf);
4994 4912666 }
4995 44336946 }
4996 else
4997 {
4998
3/4
✓ Branch 0 taken 10308985 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7085112 times.
✓ Branch 3 taken 3223873 times.
10308985 for(int32_t i=0; i<guys.Count(); i++)
4999 {
5000
13/22
✓ Branch 0 taken 7085112 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7085112 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5927067 times.
✓ Branch 5 taken 1158045 times.
✓ Branch 6 taken 5927067 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5927067 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5927067 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5474789 times.
✓ Branch 13 taken 452278 times.
✓ Branch 14 taken 5474789 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5474789 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 5474789 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5474789 times.
7085112 if((isflier(guys.spr(i)->id)) || guys.spr(i)->z > 0 || guys.spr(i)->fakez > 0)
5001 {
5002
2/4
✓ Branch 0 taken 1610323 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1610323 times.
✗ Branch 3 not taken.
1610323 guys.spr(i)->draw(framebuf);
5003 1610323 }
5004 7085112 }
5005 }
5006
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 do_primitives(framebuf, SPLAYER_NPC_AIRBORNE_DRAW);
5007
5008 // Draw the Moving Fairy above layer 3
5009
3/4
✓ Branch 0 taken 18610402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3131566 times.
✓ Branch 3 taken 15478836 times.
18610402 for(int32_t i=0; i<items.Count(); i++)
5010
6/8
✓ Branch 0 taken 3131566 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69585 times.
✓ Branch 3 taken 3061981 times.
✓ Branch 4 taken 69585 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 59871 times.
✓ Branch 7 taken 9714 times.
3191437 if(itemsbuf[items.spr(i)->id].family == itype_fairy && itemsbuf[items.spr(i)->id].misc3)
5011
2/4
✓ Branch 0 taken 59871 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59871 times.
✗ Branch 3 not taken.
59871 items.spr(i)->draw(framebuf);
5012
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 do_primitives(framebuf, SPLAYER_FAIRYITEM_DRAW);
5013
5014 // Draw some layers onto framebuf
5015
5016
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 set_draw_screen_clip(framebuf);
5017
5018
2/2
✓ Branch 0 taken 15464484 times.
✓ Branch 1 taken 14352 times.
15478836 if (lightbeam_present)
5019 {
5020 14352 color_map = &trans_table2;
5021
2/2
✓ Branch 0 taken 13114 times.
✓ Branch 1 taken 1238 times.
14352 if(get_qr(qr_LIGHTBEAM_TRANSPARENT))
5022
1/2
✓ Branch 0 taken 13114 times.
✗ Branch 1 not taken.
13114 draw_trans_sprite(framebuf, lightbeam_bmp, 0, playing_field_offset);
5023 else
5024
1/2
✓ Branch 0 taken 1238 times.
✗ Branch 1 not taken.
1238 masked_blit(lightbeam_bmp, framebuf, 0, 0, 0, playing_field_offset, 256, 176);
5025 14352 color_map = &trans_table;
5026 14352 }
5027
5028
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
31093990 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5029 15615154 do_layer(framebuf, 0, screen_handles[5], offx, offy);
5030 15615154 });
5031
5032
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 do_layer_primitives(framebuf, 5);
5033
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 particles.draw(framebuf, true, 5);
5034
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 _do_current_ffc_layer(framebuf, 5);
5035
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 draw_msgstr(5);
5036
5037
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 _do_current_ffc_layer(framebuf, -1); // 'overhead' freeform combos
5038
5039
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 do_primitives(framebuf, SPLAYER_OVERHEAD_FFC);
5040
5041
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
31093990 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5042 15615154 do_layer(framebuf, 0, screen_handles[6], offx, offy);
5043 15615154 });
5044
5045
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 do_layer_primitives(framebuf, 6);
5046
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 particles.draw(framebuf, true, 6);
5047
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 _do_current_ffc_layer(framebuf, 6);
5048
5049 15478836 bool any_dark = false;
5050
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
31093990 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5051 15615154 mapscr* base_scr = screen_handles[0].scr;
5052 15615154 any_dark |= is_dark(base_scr);
5053 15615154 });
5054
5055 // Handle low drawn darkness
5056
4/4
✓ Branch 0 taken 1274251 times.
✓ Branch 1 taken 14204585 times.
✓ Branch 2 taken 1030480 times.
✓ Branch 3 taken 243771 times.
15478836 if(get_qr(qr_NEW_DARKROOM) && any_dark)
5057 {
5058
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
493776 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5059 250005 mapscr* base_scr = screen_handles[0].scr;
5060 250005 calc_darkroom_combos(base_scr, offx, offy + playing_field_offset);
5061 250005 calc_darkroom_ffcs(base_scr, 0, playing_field_offset);
5062 250005 });
5063
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
243771 if(showhero)
5064
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
243771 Hero.calc_darkroom_hero(0, -playing_field_offset);
5065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 243771 times.
493776 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5066 250005 mapscr* base_scr = screen_handles[0].scr;
5067
2/2
✓ Branch 0 taken 245275 times.
✓ Branch 1 taken 4730 times.
250005 if (!is_dark(base_scr))
5068 {
5069 4730 offy += playing_field_offset;
5070 4730 rectfill(darkscr_bmp, offx - viewport.x, offy - viewport.y, offx - viewport.x + 256 - 1, offy - viewport.y + 176 - 1, 0);
5071 4730 rectfill(darkscr_bmp_trans, offx - viewport.x, offy - viewport.y, offx - viewport.x + 256 - 1, offy - viewport.y + 176 - 1, 0);
5072 4730 }
5073 250005 });
5074 243771 }
5075
5076 //Darkroom if under the subscreen
5077
6/6
✓ Branch 0 taken 1274251 times.
✓ Branch 1 taken 14204585 times.
✓ Branch 2 taken 823284 times.
✓ Branch 3 taken 450967 times.
✓ Branch 4 taken 231780 times.
✓ Branch 5 taken 591504 times.
15478836 if(get_qr(qr_NEW_DARKROOM) && get_qr(qr_NEWDARK_L6) && any_dark)
5078 {
5079
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 do_primitives(framebuf, SPLAYER_DARKROOM_UNDER);
5080
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 set_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
5081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 231780 times.
231780 if(hero_scr->flags9 & fDARK_DITHER) //dither the entire bitmap
5082 {
5083 ditherblit(darkscr_bmp,darkscr_bmp,0,game->get_dither_type(),game->get_dither_arg());
5084 ditherblit(darkscr_bmp_trans,darkscr_bmp_trans,0,game->get_dither_type(),game->get_dither_arg());
5085 }
5086
5087 231780 color_map = &trans_table2;
5088
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 231636 times.
231780 if(hero_scr->flags9 & fDARK_TRANS) //draw the dark as transparent
5089 {
5090
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 draw_trans_sprite(framebuf, darkscr_bmp, 0, 0);
5091
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(get_qr(qr_NEWDARK_TRANS_STACKING))
5092
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5093 144 }
5094 else
5095 {
5096
1/2
✓ Branch 0 taken 231636 times.
✗ Branch 1 not taken.
231636 masked_blit(darkscr_bmp, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
5097
1/2
✓ Branch 0 taken 231636 times.
✗ Branch 1 not taken.
231636 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5098 }
5099 231780 color_map = &trans_table;
5100
5101
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 set_clip_rect(framebuf, 0, 0, framebuf->w, framebuf->h);
5102
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 do_primitives(framebuf, SPLAYER_DARKROOM_OVER);
5103 231780 }
5104
5105
3/6
✓ Branch 0 taken 45626 times.
✓ Branch 1 taken 15433210 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45626 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
15478836 if (is_extended_height_mode() && lensclk && !FFCore.system_suspend[susptLENS])
5106 {
5107 draw_lens_over();
5108 --lensclk;
5109 }
5110
5111 // Draw some text on framebuf
5112
5113
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 set_clip_rect(framebuf,0,0,256,232);
5114
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 if(!get_qr(qr_LAYER6_STRINGS_OVER_SUBSCREEN))
5115
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 draw_msgstr(6);
5116
5117 // Draw the subscreen, without clipping
5118
2/2
✓ Branch 0 taken 6227977 times.
✓ Branch 1 taken 9250859 times.
15478836 if(get_qr(qr_SUBSCREENOVERSPRITES))
5119 {
5120
2/4
✓ Branch 0 taken 6227977 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6227977 times.
✗ Branch 3 not taken.
6227977 put_passive_subscr(framebuf, 0, 0, game->should_show_time(), sspUP);
5121
5122 // Draw primitives over subscren
5123
1/2
✓ Branch 0 taken 6227977 times.
✗ Branch 1 not taken.
6227977 do_primitives(framebuf, 7); //Layer '7' appears above subscreen if quest rule is set
5124 6227977 }
5125
5126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15478836 times.
15478836 if(get_qr(qr_LAYER6_STRINGS_OVER_SUBSCREEN))
5127 draw_msgstr(6);
5128
5129 // Handle high-drawn darkness
5130
6/6
✓ Branch 0 taken 1274251 times.
✓ Branch 1 taken 14204585 times.
✓ Branch 2 taken 450967 times.
✓ Branch 3 taken 823284 times.
✓ Branch 4 taken 11991 times.
✓ Branch 5 taken 438976 times.
15478836 if(get_qr(qr_NEW_DARKROOM) && !get_qr(qr_NEWDARK_L6) && any_dark)
5131 {
5132
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 do_primitives(framebuf, SPLAYER_DARKROOM_UNDER);
5133
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 set_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
5134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11991 times.
11991 if(hero_scr->flags9 & fDARK_DITHER) //dither the entire bitmap
5135 {
5136 ditherblit(darkscr_bmp,darkscr_bmp,0,game->get_dither_type(),game->get_dither_arg());
5137 ditherblit(darkscr_bmp_trans,darkscr_bmp_trans,0,game->get_dither_type(),game->get_dither_arg());
5138 }
5139
5140 11991 color_map = &trans_table2;
5141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11991 times.
11991 if(hero_scr->flags9 & fDARK_TRANS) //draw the dark as transparent
5142 {
5143 draw_trans_sprite(framebuf, darkscr_bmp, 0, 0);
5144 if(get_qr(qr_NEWDARK_TRANS_STACKING))
5145 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5146 }
5147 else
5148 {
5149
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 masked_blit(darkscr_bmp, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
5150
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5151 }
5152 11991 color_map = &trans_table;
5153
5154
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 set_clip_rect(framebuf, 0, 0, framebuf->w, framebuf->h);
5155
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 do_primitives(framebuf, SPLAYER_DARKROOM_OVER);
5156 11991 }
5157
5158
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 _do_current_ffc_layer(framebuf, 7);
5159
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 draw_msgstr(7);
5160
5161
1/2
✓ Branch 0 taken 15478836 times.
✗ Branch 1 not taken.
15478836 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
5162
3/4
✓ Branch 0 taken 14880226 times.
✓ Branch 1 taken 598610 times.
✓ Branch 2 taken 14880226 times.
✗ Branch 3 not taken.
15478836 if(runGeneric) FFCore.runGenericPassiveEngine(SCR_TIMING_POST_DRAW);
5163 76392388 }
5164
5165 // TODO: separate setting door data and drawing door
5166 27988 void put_door(mapscr* scr, BITMAP *dest, int32_t pos, int32_t side, int32_t type, bool redraw, bool even_walls)
5167 {
5168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27988 times.
27988 if (type > 8) return;
5169
5170 27988 int32_t d=scr->door_combo_set;
5171
5172
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 15522 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12466 times.
27988 switch(type)
5173 {
5174 case dt_wall:
5175 case dt_walk:
5176 if(!even_walls)
5177 break;
5178 [[fallthrough]];
5179 case dt_pass:
5180
3/4
✓ Branch 0 taken 1035 times.
✓ Branch 1 taken 11431 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1035 times.
12466 if(!get_qr(qr_REPLACEOPENDOORS) && !even_walls)
5181 1035 break;
5182 [[fallthrough]];
5183 case dt_lock:
5184 case dt_shut:
5185 case dt_boss:
5186 case dt_olck:
5187 case dt_osht:
5188 case dt_obos:
5189 case dt_bomb:
5190
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 7202 times.
✓ Branch 2 taken 6743 times.
✓ Branch 3 taken 6323 times.
✓ Branch 4 taken 6685 times.
26953 switch(side)
5191 {
5192 case up:
5193 7202 scr->data[pos] = DoorComboSets[d].doorcombo_u[type][0];
5194 7202 scr->cset[pos] = DoorComboSets[d].doorcset_u[type][0];
5195 7202 scr->sflag[pos] = 0;
5196 7202 scr->data[pos+1] = DoorComboSets[d].doorcombo_u[type][1];
5197 7202 scr->cset[pos+1] = DoorComboSets[d].doorcset_u[type][1];
5198 7202 scr->sflag[pos+1] = 0;
5199 7202 scr->data[pos+16] = DoorComboSets[d].doorcombo_u[type][2];
5200 7202 scr->cset[pos+16] = DoorComboSets[d].doorcset_u[type][2];
5201 7202 scr->sflag[pos+16] = 0;
5202 7202 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_u[type][3];
5203 7202 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_u[type][3];
5204 7202 scr->sflag[pos+16+1] = 0;
5205
5206
2/2
✓ Branch 0 taken 5396 times.
✓ Branch 1 taken 1806 times.
7202 if(redraw)
5207 {
5208 3612 putcombo(dest,(pos&15)<<4,pos&0xF0,
5209 1806 DoorComboSets[d].doorcombo_u[type][0],
5210 1806 DoorComboSets[d].doorcset_u[type][0]);
5211 3612 putcombo(dest,((pos&15)<<4)+16,pos&0xF0,
5212 1806 DoorComboSets[d].doorcombo_u[type][1],
5213 1806 DoorComboSets[d].doorcset_u[type][1]);
5214 1806 }
5215
5216 7202 break;
5217
5218 case down:
5219 6743 scr->data[pos] = DoorComboSets[d].doorcombo_d[type][0];
5220 6743 scr->cset[pos] = DoorComboSets[d].doorcset_d[type][0];
5221 6743 scr->sflag[pos] = 0;
5222 6743 scr->data[pos+1] = DoorComboSets[d].doorcombo_d[type][1];
5223 6743 scr->cset[pos+1] = DoorComboSets[d].doorcset_d[type][1];
5224 6743 scr->sflag[pos+1] = 0;
5225 6743 scr->data[pos+16] = DoorComboSets[d].doorcombo_d[type][2];
5226 6743 scr->cset[pos+16] = DoorComboSets[d].doorcset_d[type][2];
5227 6743 scr->sflag[pos+16] = 0;
5228 6743 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_d[type][3];
5229 6743 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_d[type][3];
5230 6743 scr->sflag[pos+16+1] = 0;
5231
5232
2/2
✓ Branch 0 taken 5429 times.
✓ Branch 1 taken 1314 times.
6743 if(redraw)
5233 {
5234 2628 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5235 1314 DoorComboSets[d].doorcombo_d[type][2],
5236 1314 DoorComboSets[d].doorcset_d[type][2]);
5237 2628 putcombo(dest,((pos&15)<<4)+16,(pos&0xF0)+16,
5238 1314 DoorComboSets[d].doorcombo_d[type][3],
5239 1314 DoorComboSets[d].doorcset_d[type][3]);
5240 1314 }
5241
5242 6743 break;
5243
5244 case left:
5245 6323 scr->data[pos] = DoorComboSets[d].doorcombo_l[type][0];
5246 6323 scr->cset[pos] = DoorComboSets[d].doorcset_l[type][0];
5247 6323 scr->sflag[pos] = 0;
5248 6323 scr->data[pos+1] = DoorComboSets[d].doorcombo_l[type][1];
5249 6323 scr->cset[pos+1] = DoorComboSets[d].doorcset_l[type][1];
5250 6323 scr->sflag[pos+1] = 0;
5251 6323 scr->data[pos+16] = DoorComboSets[d].doorcombo_l[type][2];
5252 6323 scr->cset[pos+16] = DoorComboSets[d].doorcset_l[type][2];
5253 6323 scr->sflag[pos+16] = 0;
5254 6323 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_l[type][3];
5255 6323 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_l[type][3];
5256 6323 scr->sflag[pos+16+1] = 0;
5257 6323 scr->data[pos+32] = DoorComboSets[d].doorcombo_l[type][4];
5258 6323 scr->cset[pos+32] = DoorComboSets[d].doorcset_l[type][4];
5259 6323 scr->sflag[pos+32] = 0;
5260 6323 scr->data[pos+32+1] = DoorComboSets[d].doorcombo_l[type][5];
5261 6323 scr->cset[pos+32+1] = DoorComboSets[d].doorcset_l[type][5];
5262 6323 scr->sflag[pos+32+1] = 0;
5263
5264
2/2
✓ Branch 0 taken 4842 times.
✓ Branch 1 taken 1481 times.
6323 if(redraw)
5265 {
5266 2962 putcombo(dest,(pos&15)<<4,pos&0xF0,
5267 1481 DoorComboSets[d].doorcombo_l[type][0],
5268 1481 DoorComboSets[d].doorcset_l[type][0]);
5269 2962 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5270 1481 DoorComboSets[d].doorcombo_l[type][2],
5271 1481 DoorComboSets[d].doorcset_l[type][2]);
5272 2962 putcombo(dest,(pos&15)<<4,(pos&0xF0)+32,
5273 1481 DoorComboSets[d].doorcombo_l[type][4],
5274 1481 DoorComboSets[d].doorcset_l[type][4]);
5275 1481 }
5276
5277 6323 break;
5278
5279 case right:
5280 6685 scr->data[pos] = DoorComboSets[d].doorcombo_r[type][0];
5281 6685 scr->cset[pos] = DoorComboSets[d].doorcset_r[type][0];
5282 6685 scr->sflag[pos] = 0;
5283 6685 scr->data[pos+1] = DoorComboSets[d].doorcombo_r[type][1];
5284 6685 scr->cset[pos+1] = DoorComboSets[d].doorcset_r[type][1];
5285 6685 scr->sflag[pos+1] = 0;
5286 6685 scr->data[pos+16] = DoorComboSets[d].doorcombo_r[type][2];
5287 6685 scr->cset[pos+16] = DoorComboSets[d].doorcset_r[type][2];
5288 6685 scr->sflag[pos+16] = 0;
5289 6685 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_r[type][3];
5290 6685 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_r[type][3];
5291 6685 scr->sflag[pos+16+1] = 0;
5292 6685 scr->data[pos+32] = DoorComboSets[d].doorcombo_r[type][4];
5293 6685 scr->cset[pos+32] = DoorComboSets[d].doorcset_r[type][4];
5294 6685 scr->sflag[pos+32] = 0;
5295 6685 scr->data[pos+32+1] = DoorComboSets[d].doorcombo_r[type][5];
5296 6685 scr->cset[pos+32+1] = DoorComboSets[d].doorcset_r[type][5];
5297 6685 scr->sflag[pos+32+1] = 0;
5298
5299
2/2
✓ Branch 0 taken 5031 times.
✓ Branch 1 taken 1654 times.
6685 if(redraw)
5300 {
5301 3308 putcombo(dest,(pos&15)<<4,pos&0xF0,
5302 1654 DoorComboSets[d].doorcombo_r[type][0],
5303 1654 DoorComboSets[d].doorcset_r[type][0]);
5304 3308 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5305 1654 DoorComboSets[d].doorcombo_r[type][2],
5306 1654 DoorComboSets[d].doorcset_r[type][2]);
5307 3308 putcombo(dest,(pos&15)<<4,(pos&0xF0)+32,
5308 1654 DoorComboSets[d].doorcombo_r[type][4],
5309 1654 DoorComboSets[d].doorcset_r[type][4]);
5310 1654 }
5311
5312 6685 break;
5313 }
5314
5315 26953 break;
5316
5317 default:
5318 break;
5319 }
5320 27988 }
5321
5322 697852 static void over_door(mapscr* scr, BITMAP *dest, int32_t pos, int32_t side, int32_t offx, int32_t offy)
5323 {
5324 697852 int32_t door_combo_set = scr->door_combo_set;
5325 697852 int32_t x = (pos&15)<<4;
5326 697852 int32_t y = (pos&0xF0);
5327 697852 int32_t d = door_combo_set;
5328 697852 x += offx;
5329 697852 y += offy;
5330
5331
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 156673 times.
✓ Branch 2 taken 175402 times.
✓ Branch 3 taken 196353 times.
✓ Branch 4 taken 169424 times.
697852 switch(side)
5332 {
5333 case up:
5334 313346 overcombo2(dest,x,y,
5335 156673 DoorComboSets[d].bombdoorcombo_u[0],
5336 156673 DoorComboSets[d].bombdoorcset_u[0]);
5337 313346 overcombo2(dest,x+16,y,
5338 156673 DoorComboSets[d].bombdoorcombo_u[1],
5339 156673 DoorComboSets[d].bombdoorcset_u[1]);
5340 156673 break;
5341
5342 case down:
5343 350804 overcombo2(dest,x,y,
5344 175402 DoorComboSets[d].bombdoorcombo_d[0],
5345 175402 DoorComboSets[d].bombdoorcset_d[0]);
5346 350804 overcombo2(dest,x+16,y,
5347 175402 DoorComboSets[d].bombdoorcombo_d[1],
5348 175402 DoorComboSets[d].bombdoorcset_d[1]);
5349 175402 break;
5350
5351 case left:
5352 392706 overcombo2(dest,x,y,
5353 196353 DoorComboSets[d].bombdoorcombo_l[0],
5354 196353 DoorComboSets[d].bombdoorcset_l[0]);
5355 392706 overcombo2(dest,x,y+16,
5356 196353 DoorComboSets[d].bombdoorcombo_l[1],
5357 196353 DoorComboSets[d].bombdoorcset_l[1]);
5358 392706 overcombo2(dest,x,y+16,
5359 196353 DoorComboSets[d].bombdoorcombo_l[2],
5360 196353 DoorComboSets[d].bombdoorcset_l[2]);
5361 196353 break;
5362
5363 case right:
5364 338848 overcombo2(dest,x,y,
5365 169424 DoorComboSets[d].bombdoorcombo_r[0],
5366 169424 DoorComboSets[d].bombdoorcset_r[0]);
5367 338848 overcombo2(dest,x,y+16,
5368 169424 DoorComboSets[d].bombdoorcombo_r[1],
5369 169424 DoorComboSets[d].bombdoorcset_r[1]);
5370 338848 overcombo2(dest,x,y+16,
5371 169424 DoorComboSets[d].bombdoorcombo_r[2],
5372 169424 DoorComboSets[d].bombdoorcset_r[2]);
5373 169424 break;
5374 }
5375 697852 }
5376
5377 47328 void update_door(mapscr* scr, int32_t side, int32_t door, bool even_walls)
5378 {
5379
7/8
✓ Branch 0 taken 47220 times.
✓ Branch 1 taken 108 times.
✓ Branch 2 taken 47220 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22791 times.
✓ Branch 5 taken 24429 times.
✓ Branch 6 taken 530 times.
✓ Branch 7 taken 22261 times.
47328 if(door == dNONE || (!even_walls&&(door==dWALL||door==dWALK)))
5380 25067 return;
5381
5382 int32_t doortype;
5383
5384
10/12
✓ Branch 0 taken 522 times.
✓ Branch 1 taken 653 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 12416 times.
✓ Branch 5 taken 903 times.
✓ Branch 6 taken 1541 times.
✓ Branch 7 taken 3179 times.
✓ Branch 8 taken 1684 times.
✓ Branch 9 taken 169 times.
✓ Branch 10 taken 66 times.
✓ Branch 11 taken 1128 times.
22261 switch(door)
5385 {
5386 case dWALL:
5387 doortype=dt_wall;
5388 break;
5389
5390 case dWALK:
5391 doortype=dt_walk;
5392 break;
5393
5394 case dOPEN:
5395 12416 doortype=dt_pass;
5396 12416 break;
5397
5398 case dLOCKED:
5399 903 doortype=dt_lock;
5400 903 break;
5401
5402 case dUNLOCKED:
5403 1541 doortype=dt_olck;
5404 1541 break;
5405
5406 case dSHUTTER:
5407
3/4
✓ Branch 0 taken 2770 times.
✓ Branch 1 taken 409 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2770 times.
3179 if(screenscrolling && ((HeroDir()^1)==side))
5408 {
5409 doortype=dt_osht;
5410 get_screen_state(scr->screen).open_doors = -4;
5411 break;
5412 }
5413
5414 [[fallthrough]];
5415 case d1WAYSHUTTER:
5416 3701 doortype=dt_shut;
5417 3701 break;
5418
5419 case dOPENSHUTTER:
5420 1684 doortype=dt_osht;
5421 1684 break;
5422
5423 case dBOSS:
5424 169 doortype=dt_boss;
5425 169 break;
5426
5427 case dOPENBOSS:
5428 66 doortype=dt_obos;
5429 66 break;
5430
5431 case dBOMBED:
5432 1128 doortype=dt_bomb;
5433 1128 break;
5434
5435 default:
5436 653 return;
5437 }
5438
5439
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 5590 times.
✓ Branch 2 taken 5736 times.
✓ Branch 3 taken 5079 times.
✓ Branch 4 taken 5203 times.
21608 switch(side)
5440 {
5441 case up:
5442 5590 put_door(scr,nullptr,7,side,doortype,false,even_walls);
5443 5590 break;
5444
5445 case down:
5446 5736 put_door(scr,nullptr,151,side,doortype,false,even_walls);
5447 5736 break;
5448
5449 case left:
5450 5079 put_door(scr,nullptr,64,side,doortype,false,even_walls);
5451 5079 break;
5452
5453 case right:
5454 5203 put_door(scr,nullptr,78,side,doortype,false,even_walls);
5455 5203 break;
5456 }
5457 47328 }
5458
5459 6471 void putdoor(mapscr* scr, BITMAP *dest, int32_t side, int32_t door, bool redraw, bool even_walls)
5460 {
5461 /*
5462 #define dWALL 0 // 000 0
5463 #define dBOMB 6 // 011 0
5464 #define 8 // 100 0
5465 enum {dt_pass=0, dt_lock, dt_shut, dt_boss, dt_olck, dt_osht, dt_obos, dt_wall, dt_bomb, dt_walk, dt_max};
5466 */
5467
5468
7/8
✓ Branch 0 taken 6471 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6467 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 6384 times.
✓ Branch 5 taken 83 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 6376 times.
6471 if(door == dNONE || (!even_walls&&(door==dWALL||door==dWALK)))
5469 91 return;
5470
5471 int32_t doortype;
5472
5473
8/12
✓ Branch 0 taken 227 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 359 times.
✓ Branch 7 taken 1520 times.
✓ Branch 8 taken 3941 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 50 times.
✓ Branch 11 taken 229 times.
6380 switch(door)
5474 {
5475 case dWALL:
5476 doortype=dt_wall;
5477 break;
5478
5479 case dWALK:
5480 doortype=dt_walk;
5481 break;
5482
5483 case dOPEN:
5484 50 doortype=dt_pass;
5485 50 break;
5486
5487 case dLOCKED:
5488 doortype=dt_lock;
5489 break;
5490
5491 case dUNLOCKED:
5492 359 doortype=dt_olck;
5493 359 break;
5494
5495 case dSHUTTER:
5496
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1520 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1520 if(screenscrolling && ((HeroDir()^1)==side))
5497 {
5498 doortype=dt_osht;
5499 get_screen_state(cur_screen).open_doors = -4;
5500 break;
5501 }
5502
5503 [[fallthrough]];
5504 case d1WAYSHUTTER:
5505 1747 doortype=dt_shut;
5506 1747 break;
5507
5508 case dOPENSHUTTER:
5509 3941 doortype=dt_osht;
5510 3941 break;
5511
5512 case dBOSS:
5513 4 doortype=dt_boss;
5514 4 break;
5515
5516 case dOPENBOSS:
5517 50 doortype=dt_obos;
5518 50 break;
5519
5520 case dBOMBED:
5521 229 doortype=dt_bomb;
5522 229 break;
5523
5524 default:
5525 return;
5526 }
5527
5528
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 1842 times.
✓ Branch 2 taken 1350 times.
✓ Branch 3 taken 1506 times.
✓ Branch 4 taken 1682 times.
6380 switch(side)
5529 {
5530 case up:
5531
2/2
✓ Branch 0 taken 1775 times.
✓ Branch 1 taken 67 times.
1842 switch(door)
5532 {
5533 case dBOMBED:
5534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
134 if(redraw)
5535 {
5536 67 over_door(scr,dest,39,side,0,0);
5537 67 }
5538 [[fallthrough]];
5539 default:
5540 1842 put_door(scr,dest,7,side,doortype,redraw, even_walls);
5541 1842 break;
5542 }
5543
5544 1842 break;
5545
5546 case down:
5547
2/2
✓ Branch 0 taken 1311 times.
✓ Branch 1 taken 39 times.
1350 switch(door)
5548 {
5549 case dBOMBED:
5550
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
78 if(redraw)
5551 {
5552 39 over_door(scr,dest,135,side,0,0);
5553 39 }
5554 [[fallthrough]];
5555 default:
5556 1350 put_door(scr,dest,151,side,doortype,redraw, even_walls);
5557 1350 break;
5558 }
5559
5560 1350 break;
5561
5562 case left:
5563
2/2
✓ Branch 0 taken 1455 times.
✓ Branch 1 taken 51 times.
1506 switch(door)
5564 {
5565 case dBOMBED:
5566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
102 if(redraw)
5567 {
5568 51 over_door(scr,dest,66,side,0,0);
5569 51 }
5570 [[fallthrough]];
5571 default:
5572 1506 put_door(scr,dest,64,side,doortype,redraw, even_walls);
5573 1506 break;
5574 }
5575
5576 1506 break;
5577
5578 case right:
5579
2/2
✓ Branch 0 taken 1610 times.
✓ Branch 1 taken 72 times.
1682 switch(door)
5580 {
5581 case dBOMBED:
5582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
144 if(redraw)
5583 {
5584 72 over_door(scr,dest,77,side,0,0);
5585 72 }
5586 [[fallthrough]];
5587 default:
5588 1682 put_door(scr,dest,78,side,doortype,redraw, even_walls);
5589 1682 break;
5590 }
5591
5592 1682 break;
5593 }
5594 6471 }
5595
5596 586 void putcombo_not_zero(BITMAP *dest, int32_t x, int32_t y, int32_t combo, int32_t cset)
5597 {
5598
1/2
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
586 if(combo!=0)
5599 {
5600 586 putcombo(dest,x, y, combo, cset);
5601 586 }
5602 586 }
5603
5604 293 void overcombo_not_zero(BITMAP *dest, int32_t x, int32_t y, int32_t combo, int32_t cset)
5605 {
5606
2/2
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 74 times.
293 if(combo!=0)
5607 {
5608 219 overcombo(dest,x, y, combo, cset);
5609 219 }
5610 293 }
5611
5612 125 void showbombeddoor(mapscr* scr, BITMAP *dest, int32_t side, int32_t offx, int32_t offy)
5613 {
5614 125 int32_t d = scr->door_combo_set;
5615
5616
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 39 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 37 times.
125 switch(side)
5617 {
5618 case up:
5619 86 putcombo_not_zero(dest,((7&15)<<4) + offx,(7&0xF0) + offy,
5620 43 DoorComboSets[d].doorcombo_u[dt_bomb][0],
5621 43 DoorComboSets[d].doorcset_u[dt_bomb][0]);
5622 86 putcombo_not_zero(dest,((8&15)<<4) + offx,(8&0xF0) + offy,
5623 43 DoorComboSets[d].doorcombo_u[dt_bomb][1],
5624 43 DoorComboSets[d].doorcset_u[dt_bomb][1]);
5625 86 putcombo_not_zero(dest,((23&15)<<4) + offx,(23&0xF0) + offy,
5626 43 DoorComboSets[d].doorcombo_u[dt_bomb][2],
5627 43 DoorComboSets[d].doorcset_u[dt_bomb][2]);
5628 86 putcombo_not_zero(dest,((24&15)<<4) + offx,(24&0xF0) + offy,
5629 43 DoorComboSets[d].doorcombo_u[dt_bomb][3],
5630 43 DoorComboSets[d].doorcset_u[dt_bomb][3]);
5631 86 overcombo_not_zero(dest,((39&15)<<4) + offx,(39&0xF0) + offy,
5632 43 DoorComboSets[d].bombdoorcombo_u[0],
5633 43 DoorComboSets[d].bombdoorcset_u[0]);
5634 86 overcombo_not_zero(dest,((40&15)<<4) + offx,(40&0xF0) + offy,
5635 43 DoorComboSets[d].bombdoorcombo_u[1],
5636 43 DoorComboSets[d].bombdoorcset_u[1]);
5637 43 break;
5638
5639 case down:
5640 78 putcombo_not_zero(dest,((151&15)<<4) + offx,(151&0xF0) + offy,
5641 39 DoorComboSets[d].doorcombo_d[dt_bomb][0],
5642 39 DoorComboSets[d].doorcset_d[dt_bomb][0]);
5643 78 putcombo_not_zero(dest,((152&15)<<4) + offx,(152&0xF0) + offy,
5644 39 DoorComboSets[d].doorcombo_d[dt_bomb][1],
5645 39 DoorComboSets[d].doorcset_d[dt_bomb][1]);
5646 78 putcombo_not_zero(dest,((167&15)<<4) + offx,(167&0xF0) + offy,
5647 39 DoorComboSets[d].doorcombo_d[dt_bomb][2],
5648 39 DoorComboSets[d].doorcset_d[dt_bomb][2]);
5649 78 putcombo_not_zero(dest,((168&15)<<4) + offx,(168&0xF0) + offy,
5650 39 DoorComboSets[d].doorcombo_d[dt_bomb][3],
5651 39 DoorComboSets[d].doorcset_d[dt_bomb][3]);
5652 78 overcombo_not_zero(dest,((135&15)<<4) + offx,(135&0xF0) + offy,
5653 39 DoorComboSets[d].bombdoorcombo_d[0],
5654 39 DoorComboSets[d].bombdoorcset_d[0]);
5655 78 overcombo_not_zero(dest,((136&15)<<4) + offx,(136&0xF0) + offy,
5656 39 DoorComboSets[d].bombdoorcombo_d[1],
5657 39 DoorComboSets[d].bombdoorcset_d[1]);
5658 39 break;
5659
5660 case left:
5661 12 putcombo_not_zero(dest,((64&15)<<4) + offx,(64&0xF0) + offy,
5662 6 DoorComboSets[d].doorcombo_l[dt_bomb][0],
5663 6 DoorComboSets[d].doorcset_l[dt_bomb][0]);
5664 12 putcombo_not_zero(dest,((65&15)<<4) + offx,(65&0xF0) + offy,
5665 6 DoorComboSets[d].doorcombo_l[dt_bomb][1],
5666 6 DoorComboSets[d].doorcset_l[dt_bomb][1]);
5667 12 putcombo_not_zero(dest,((80&15)<<4) + offx,(80&0xF0) + offy,
5668 6 DoorComboSets[d].doorcombo_l[dt_bomb][2],
5669 6 DoorComboSets[d].doorcset_l[dt_bomb][2]);
5670 12 putcombo_not_zero(dest,((81&15)<<4) + offx,(81&0xF0) + offy,
5671 6 DoorComboSets[d].doorcombo_l[dt_bomb][3],
5672 6 DoorComboSets[d].doorcset_l[dt_bomb][3]);
5673 12 putcombo_not_zero(dest,((96&15)<<4) + offx,(96&0xF0) + offy,
5674 6 DoorComboSets[d].doorcombo_l[dt_bomb][4],
5675 6 DoorComboSets[d].doorcset_l[dt_bomb][4]);
5676 12 putcombo_not_zero(dest,((97&15)<<4) + offx,(97&0xF0) + offy,
5677 6 DoorComboSets[d].doorcombo_l[dt_bomb][5],
5678 6 DoorComboSets[d].doorcset_l[dt_bomb][5]);
5679 12 overcombo_not_zero(dest,((66&15)<<4) + offx,(66&0xF0) + offy,
5680 6 DoorComboSets[d].bombdoorcombo_l[0],
5681 6 DoorComboSets[d].bombdoorcset_l[0]);
5682 12 overcombo_not_zero(dest,((82&15)<<4) + offx,(82&0xF0) + offy,
5683 6 DoorComboSets[d].bombdoorcombo_l[1],
5684 6 DoorComboSets[d].bombdoorcset_l[1]);
5685 12 overcombo_not_zero(dest,((98&15)<<4) + offx,(98&0xF0) + offy,
5686 6 DoorComboSets[d].bombdoorcombo_l[2],
5687 6 DoorComboSets[d].bombdoorcset_l[2]);
5688 6 break;
5689
5690 case right:
5691 74 putcombo_not_zero(dest,((78&15)<<4) + offx,(78&0xF0) + offy,
5692 37 DoorComboSets[d].doorcombo_r[dt_bomb][0],
5693 37 DoorComboSets[d].doorcset_r[dt_bomb][0]);
5694 74 putcombo_not_zero(dest,((79&15)<<4) + offx,(79&0xF0) + offy,
5695 37 DoorComboSets[d].doorcombo_r[dt_bomb][1],
5696 37 DoorComboSets[d].doorcset_r[dt_bomb][1]);
5697 74 putcombo_not_zero(dest,((94&15)<<4) + offx,(94&0xF0) + offy,
5698 37 DoorComboSets[d].doorcombo_r[dt_bomb][2],
5699 37 DoorComboSets[d].doorcset_r[dt_bomb][2]);
5700 74 putcombo_not_zero(dest,((95&15)<<4) + offx,(95&0xF0) + offy,
5701 37 DoorComboSets[d].doorcombo_r[dt_bomb][3],
5702 37 DoorComboSets[d].doorcset_r[dt_bomb][3]);
5703 74 putcombo_not_zero(dest,((110&15)<<4) + offx,(110&0xF0) + offy,
5704 37 DoorComboSets[d].doorcombo_r[dt_bomb][4],
5705 37 DoorComboSets[d].doorcset_r[dt_bomb][4]);
5706 74 putcombo_not_zero(dest,((111&15)<<4) + offx,(111&0xF0) + offy,
5707 37 DoorComboSets[d].doorcombo_r[dt_bomb][5],
5708 37 DoorComboSets[d].doorcset_r[dt_bomb][5]);
5709 74 overcombo_not_zero(dest,((77&15)<<4) + offx,(77&0xF0) + offy,
5710 37 DoorComboSets[d].bombdoorcombo_r[0],
5711 37 DoorComboSets[d].bombdoorcset_r[0]);
5712 74 overcombo_not_zero(dest,((93&15)<<4) + offx,(93&0xF0) + offy,
5713 37 DoorComboSets[d].bombdoorcombo_r[1],
5714 37 DoorComboSets[d].bombdoorcset_r[1]);
5715 74 overcombo_not_zero(dest,((109&15)<<4) + offx,(109&0xF0) + offy,
5716 37 DoorComboSets[d].bombdoorcombo_r[2],
5717 37 DoorComboSets[d].bombdoorcset_r[2]);
5718 37 break;
5719 }
5720 125 }
5721
5722 5349366 void openshutters(mapscr* scr)
5723 {
5724 5349366 bool opened_door = false;
5725
2/2
✓ Branch 0 taken 5349366 times.
✓ Branch 1 taken 21397464 times.
26746830 for(int32_t i=0; i<4; i++)
5726
2/2
✓ Branch 0 taken 21393523 times.
✓ Branch 1 taken 3941 times.
21401405 if(scr->door[i]==dSHUTTER)
5727 {
5728 3941 putdoor(scr, scrollbuf, i, dOPENSHUTTER);
5729 3941 scr->door[i]=dOPENSHUTTER;
5730 3941 opened_door = true;
5731 3941 }
5732
5733 5349366 auto& combo_cache = combo_caches::shutter;
5734 2018257190 for_every_combo_in_screen(create_screen_handles(scr), [&](const auto& handle) {
5735
3/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 2011297179 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1610624 times.
2012907824 if (!combo_cache.minis[handle.data()].shutter)
5736 2012907803 return;
5737 21 auto cid = handle.data();
5738 21 auto& cmb = handle.combo();
5739
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
39 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
5740 {
5741 39 auto& trig = cmb.triggers[idx];
5742
2/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
39 if(trig.triggerflags[0] & combotriggerSHUTTER)
5743 {
5744 21 do_trigger_combo(handle, idx);
5745
1/4
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
21 if(handle.data() != cid) break;
5746 }
5747 18 }
5748 2012907824 });
5749
5750
2/2
✓ Branch 0 taken 5346651 times.
✓ Branch 1 taken 2715 times.
5349366 if(opened_door)
5751 2715 sfx(WAV_DOOR,128);
5752 5349366 }
5753
5754 15060224 void clear_darkroom_bitmaps()
5755 {
5756 15060224 clear_to_color(darkscr_bmp, game->get_darkscr_color());
5757 15060224 clear_to_color(darkscr_bmp_trans, game->get_darkscr_color());
5758 15060224 }
5759
5760 15969904 bool is_dark(const mapscr* scr)
5761 {
5762 15969904 bool dark = scr->flags&fDARK;
5763
2/2
✓ Branch 0 taken 3722 times.
✓ Branch 1 taken 15966182 times.
15969904 if (region_is_lit) return !dark;
5764 15966182 return dark;
5765 15969904 }
5766
5767 39141 bool scrolling_is_dark(const mapscr* scr)
5768 {
5769 39141 bool dark = scr->flags&fDARK;
5770
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 39139 times.
39141 if (scrolling_region_is_lit) return !dark;
5771 39139 return dark;
5772 39141 }
5773
5774 36660 bool is_any_dark()
5775 {
5776 36660 bool dark = false;
5777 74576 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
5778 37916 dark |= (bool)(is_dark(scr));
5779 37916 });
5780 36660 return dark;
5781 }
5782
5783 408 static mapscr prev_origin_scrs[7];
5784 408 static std::set<int> loadscr_ffc_script_ids_to_remove;
5785
5786 static void handle_screen_overlay(const std::vector<mapscr*>& screens)
5787 {
5788 mapscr* base_scr = screens[0];
5789 mapscr* previous_scr = &prev_origin_scrs[0];
5790
5791 for (int i = 0; i < 176; i++)
5792 {
5793 if (base_scr->data[i] == 0)
5794 {
5795 base_scr->data[i] = previous_scr->data[i];
5796 base_scr->sflag[i] = previous_scr->sflag[i];
5797 base_scr->cset[i] = previous_scr->cset[i];
5798 }
5799 }
5800
5801 for (int i = 0; i < 6; i++)
5802 {
5803 if (previous_scr->layermap[i] > 0 && base_scr->layermap[i] > 0)
5804 {
5805 int lm = (base_scr->layermap[i]-1)*MAPSCRS+base_scr->layerscreen[i];
5806 int fm = (previous_scr->layermap[i]-1)*MAPSCRS+previous_scr->layerscreen[i];
5807
5808 for (int j = 0; j < 176; j++)
5809 {
5810 if (TheMaps[lm].data[j] == 0)
5811 {
5812 TheMaps[lm].data[j] = TheMaps[fm].data[j];
5813 TheMaps[lm].sflag[j] = TheMaps[fm].sflag[j];
5814 TheMaps[lm].cset[j] = TheMaps[fm].cset[j];
5815 }
5816 }
5817 }
5818 }
5819
5820 for (int i = 1; i <= 6; i++)
5821 {
5822 mapscr* scr = screens[i];
5823 previous_scr = &prev_origin_scrs[i];
5824
5825 if (scr->layermap[i] > 0)
5826 {
5827 for (int y = 0; y < 11; y++)
5828 {
5829 for (int x = 0; x < 16; x++)
5830 {
5831 int c = y*16+x;
5832
5833 if (scr->data[c]==0)
5834 {
5835 scr->data[c] = previous_scr->data[c];
5836 scr->sflag[c] = previous_scr->sflag[c];
5837 scr->cset[c] = previous_scr->cset[c];
5838 }
5839 }
5840 }
5841 }
5842 }
5843 }
5844
5845 37000 static void load_a_screen_and_layers_init(int dmap, int screen, int ldir, bool screen_overlay, bool ffc_overlay)
5846 {
5847 37000 std::vector<mapscr*> screens;
5848
5849
1/2
✓ Branch 0 taken 37000 times.
✗ Branch 1 not taken.
37000 const mapscr* source = get_canonical_scr(cur_map, screen);
5850
2/4
✓ Branch 0 taken 37000 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37000 times.
✗ Branch 3 not taken.
37000 mapscr* base_scr = new mapscr(*source);
5851 37000 temporary_screens[screen*7] = base_scr;
5852
1/2
✓ Branch 0 taken 37000 times.
✗ Branch 1 not taken.
37000 screens.push_back(base_scr);
5853
5854 37000 base_scr->valid |= mVALID; // layer 0 is always valid
5855
5856
2/2
✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 35756 times.
37000 if (screen == cur_screen)
5857 35756 origin_scr = base_scr;
5858
2/2
✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 35756 times.
37000 if (screen == hero_screen)
5859 35756 hero_scr = prev_hero_scr = base_scr;
5860
5861
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 36881 times.
37000 if (source->script > 0)
5862
1/2
✓ Branch 0 taken 119 times.
✗ Branch 1 not taken.
119 FFCore.reset_script_engine_data(ScriptType::Screen, screen);
5863
5864
2/2
✓ Branch 0 taken 37000 times.
✓ Branch 1 taken 222000 times.
259000 for (int i = 0; i < 6; i++)
5865 {
5866
2/2
✓ Branch 0 taken 173037 times.
✓ Branch 1 taken 48963 times.
222000 if(source->layermap[i]>0)
5867 {
5868
3/6
✓ Branch 0 taken 48963 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48963 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48963 times.
✗ Branch 5 not taken.
48963 mapscr* layer_scr = new mapscr(*get_canonical_scr(source->layermap[i]-1, source->layerscreen[i]));
5869 48963 layer_scr->map = cur_map;
5870 48963 layer_scr->screen = screen;
5871
1/2
✓ Branch 0 taken 48963 times.
✗ Branch 1 not taken.
48963 screens.push_back(layer_scr);
5872 48963 }
5873 else
5874 {
5875
1/2
✓ Branch 0 taken 173037 times.
✗ Branch 1 not taken.
173037 mapscr* layer_scr = new mapscr();
5876 173037 layer_scr->map = cur_map;
5877 173037 layer_scr->screen = screen;
5878
1/2
✓ Branch 0 taken 173037 times.
✗ Branch 1 not taken.
173037 screens.push_back(layer_scr);
5879 }
5880 222000 temporary_screens[screen*7+i+1] = screens[i+1];
5881 222000 }
5882
5883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37000 times.
37000 if (screen_overlay)
5884 handle_screen_overlay(screens);
5885
5886
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 36856 times.
37000 if (ffc_overlay)
5887 {
5888 144 mapscr* previous_scr = &prev_origin_scrs[0];
5889
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 int num_ffcs = previous_scr->numFFC();
5890
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 144 times.
4752 for (int i = 0; i < num_ffcs; i++)
5891 {
5892
2/2
✓ Branch 0 taken 4334 times.
✓ Branch 1 taken 274 times.
4608 if ((previous_scr->ffcs[i].flags&ffc_carryover))
5893 {
5894
2/4
✓ Branch 0 taken 274 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 274 times.
✗ Branch 3 not taken.
274 auto& ffc = base_scr->getFFC(i) = previous_scr->ffcs[i];
5895 274 ffc.screen_spawned = screen;
5896
5897
1/2
✓ Branch 0 taken 274 times.
✗ Branch 1 not taken.
274 ffc_id_t ffc_id = get_region_screen_offset(screen)*MAXFFCS + i;
5898
1/2
✓ Branch 0 taken 274 times.
✗ Branch 1 not taken.
274 loadscr_ffc_script_ids_to_remove.erase(ffc_id);
5899
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 274 times.
274 if (previous_scr->ffcs[i].flags&ffc_scriptreset)
5900 {
5901 FFCore.reset_script_engine_data(ScriptType::FFC, ffc_id);
5902 }
5903 274 }
5904 4608 }
5905 144 }
5906
5907
1/2
✓ Branch 0 taken 37000 times.
✗ Branch 1 not taken.
1138713 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
5908
1/2
✓ Branch 0 taken 37000 times.
✗ Branch 1 not taken.
37000 int num_ffcs = base_scr->numFFC();
5909
2/2
✓ Branch 0 taken 1101713 times.
✓ Branch 1 taken 37000 times.
1138713 for (word i = 0; i < num_ffcs; i++)
5910 {
5911 1101713 base_scr->ffcs[i].screen_spawned = screen;
5912
1/2
✓ Branch 0 taken 1101713 times.
✗ Branch 1 not taken.
1101713 base_scr->ffcs[i].x += offx;
5913
1/2
✓ Branch 0 taken 1101713 times.
✗ Branch 1 not taken.
1101713 base_scr->ffcs[i].y += offy;
5914 1101713 }
5915 37000 }
5916
5917 37000 static void load_a_screen_and_layers_post(int dmap, int screen, int ldir)
5918 {
5919 37000 mapscr* base_scr = get_scr(screen);
5920 37000 int mi = mapind(cur_map, screen);
5921
5922 // Apply perm secrets, if applicable.
5923
2/2
✓ Branch 0 taken 11460 times.
✓ Branch 1 taken 25540 times.
37000 if (canPermSecret(dmap, screen))
5924 {
5925
2/2
✓ Branch 0 taken 23017 times.
✓ Branch 1 taken 2523 times.
25540 if(game->maps[mi] & mSECRET) // if special stuff done before
5926 {
5927 2523 reveal_hidden_stairs(base_scr, screen, false);
5928 2523 trigger_secrets_for_screen(TriggerSource::SecretsScreenState, base_scr, false);
5929 2523 }
5930
2/2
✓ Branch 0 taken 25537 times.
✓ Branch 1 taken 3 times.
25540 if(game->maps[mi] & mLIGHTBEAM) // if special stuff done before
5931 {
5932
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 3 times.
24 for (int layer = 0; layer <= 6; layer++)
5933 {
5934 21 mapscr* layer_scr = get_scr_layer(screen, layer);
5935
2/2
✓ Branch 0 taken 3696 times.
✓ Branch 1 taken 21 times.
3717 for (int pos = 0; pos < 176; pos++)
5936 {
5937 3696 newcombo const* cmb = &combobuf[layer_scr->data[pos]];
5938
2/2
✓ Branch 0 taken 3693 times.
✓ Branch 1 taken 3 times.
3696 if(cmb->type == cLIGHTTARGET)
5939 {
5940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!(cmb->usrflags&cflag1)) //Unlit version
5941 {
5942 3 layer_scr->data[pos] += 1;
5943 3 }
5944 3 }
5945 3696 }
5946 21 }
5947 3 }
5948 25540 }
5949
5950 37000 auto screen_handles = create_screen_handles(base_scr);
5951
5952 37000 int destlvl = DMaps[dmap].level;
5953 37000 toggle_switches(game->lvlswitches[destlvl], true, screen_handles);
5954 37000 toggle_gswitches_load(screen_handles);
5955
5956 37000 bool should_check_for_state_things = (screen < 0x80);
5957
2/2
✓ Branch 0 taken 903 times.
✓ Branch 1 taken 36097 times.
37000 if (should_check_for_state_things)
5958 {
5959
2/2
✓ Branch 0 taken 35725 times.
✓ Branch 1 taken 372 times.
36097 if (game->maps[mi]&mLOCKBLOCK)
5960 372 remove_lockblocks(screen_handles);
5961
2/2
✓ Branch 0 taken 36039 times.
✓ Branch 1 taken 58 times.
36097 if (game->maps[mi]&mBOSSLOCKBLOCK)
5962 58 remove_bosslockblocks(screen_handles);
5963
2/2
✓ Branch 0 taken 35941 times.
✓ Branch 1 taken 156 times.
36097 if (game->maps[mi]&mCHEST)
5964 156 remove_chests(screen_handles);
5965
1/2
✓ Branch 0 taken 36097 times.
✗ Branch 1 not taken.
36097 if (game->maps[mi]&mLOCKEDCHEST)
5966 remove_lockedchests(screen_handles);
5967
2/2
✓ Branch 0 taken 36086 times.
✓ Branch 1 taken 11 times.
36097 if (game->maps[mi]&mBOSSCHEST)
5968 11 remove_bosschests(screen_handles);
5969
5970 36097 clear_xdoors_mi(screen_handles, mi, true);
5971 36097 clear_xstatecombos_mi(screen_handles, mi, true);
5972 36097 }
5973
5974 // check doors
5975
2/2
✓ Branch 0 taken 25539 times.
✓ Branch 1 taken 11461 times.
37000 if (isdungeon(dmap, screen))
5976 {
5977
2/2
✓ Branch 0 taken 45844 times.
✓ Branch 1 taken 11461 times.
57305 for(int32_t i=0; i<4; i++)
5978 {
5979 45844 int32_t door=base_scr->door[i];
5980
5981
5/5
✓ Branch 0 taken 5280 times.
✓ Branch 1 taken 36293 times.
✓ Branch 2 taken 2353 times.
✓ Branch 3 taken 226 times.
✓ Branch 4 taken 1692 times.
45844 switch(door)
5982 {
5983 case d1WAYSHUTTER:
5984 case dSHUTTER:
5985
3/4
✓ Branch 0 taken 1684 times.
✓ Branch 1 taken 3596 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1684 times.
5280 if ((ldir^1)==i && screen == hero_screen)
5986 {
5987 1684 base_scr->door[i]=dOPENSHUTTER;
5988 1684 }
5989
5990 5280 get_screen_state(screen).open_doors = -4;
5991 5280 break;
5992
5993 case dLOCKED:
5994
3/4
✓ Branch 0 taken 2353 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1461 times.
✓ Branch 3 taken 892 times.
2353 if(should_check_for_state_things && game->maps[mi]&(1<<i))
5995 {
5996 1461 base_scr->door[i]=dUNLOCKED;
5997 1461 }
5998
5999 2353 break;
6000
6001 case dBOSS:
6002
3/4
✓ Branch 0 taken 226 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
✓ Branch 3 taken 165 times.
226 if(should_check_for_state_things && game->maps[mi]&(1<<i))
6003 {
6004 61 base_scr->door[i]=dOPENBOSS;
6005 61 }
6006
6007 226 break;
6008
6009 case dBOMB:
6010
3/4
✓ Branch 0 taken 1692 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1077 times.
✓ Branch 3 taken 615 times.
1692 if(should_check_for_state_things && game->maps[mi]&(1<<i))
6011 {
6012 1077 base_scr->door[i]=dBOMBED;
6013 1077 }
6014
6015 1692 break;
6016 }
6017
6018 45844 update_door(base_scr, i, base_scr->door[i]);
6019
6020
4/4
✓ Branch 0 taken 41300 times.
✓ Branch 1 taken 4544 times.
✓ Branch 2 taken 736 times.
✓ Branch 3 taken 40564 times.
45844 if(door==dSHUTTER||door==d1WAYSHUTTER)
6021 {
6022 5280 base_scr->door[i]=door;
6023 5280 }
6024 45844 }
6025 11461 }
6026
6027
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 36863 times.
37000 if (!(base_scr->flags3 & fCYCLEONINIT))
6028 36863 return;
6029
6030
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 959 times.
1096 for (int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6031 {
6032
4/4
✓ Branch 0 taken 822 times.
✓ Branch 1 taken 137 times.
✓ Branch 2 taken 377 times.
✓ Branch 3 taken 445 times.
959 if (j<0 || base_scr->layermap[j] > 0)
6033 {
6034 514 mapscr* layer_scr = get_scr_layer(screen, j + 1);
6035
3/4
✓ Branch 0 taken 377 times.
✓ Branch 1 taken 137 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 377 times.
514 mapscr* layerscreen= (j<0 ? base_scr : layer_scr->valid ? layer_scr :
6036 &TheMaps[(base_scr->layermap[j]-1)*MAPSCRS]+base_scr->layerscreen[j]);
6037
6038
2/2
✓ Branch 0 taken 90464 times.
✓ Branch 1 taken 514 times.
90978 for(int32_t i=0; i<176; ++i)
6039 {
6040 90464 int32_t c=layerscreen->data[i];
6041
6042 // New screen flag: Cycle Combos At Screen Init
6043
5/6
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 90399 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 29 times.
✗ Branch 5 not taken.
90464 if(combobuf[c].nextcombo != 0 && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6044 {
6045 65 int32_t r = 0;
6046
6047
4/4
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 65 times.
149 while(combobuf[c].can_cycle() && r++ < 10)
6048 {
6049 84 newcombo const& cmb = combobuf[c];
6050 84 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6052 84 layerscreen->data[i] = cid;
6053
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 69 times.
84 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
69 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6055 84 c = layerscreen->data[i];
6056 }
6057 65 }
6058 90464 }
6059 514 }
6060 959 }
6061 37000 }
6062
6063 // Set `cur_screen` to `screen` and load new screens into temporary memory.
6064 //
6065 // Called anytime a player moves to a new screen (either via warping, scrolling, continue, starting
6066 // the game, etc...)
6067 //
6068 // Note: for regions, only the initial screen load calls this function. Simply walking between
6069 // screens in the same region does not use this, because every screen in a region is loaded into
6070 // temporary memory up front.
6071 //
6072 // If scr >= 0x80, `hero_screen` will be saved to `home_screen` and also be loaded into
6073 // `special_warp_return_scr`.
6074 //
6075 // If origin_screen_overlay is true, the old origin_scr combos will be copied to the new origin_scr combos
6076 // on all layers (but only where the new screen has a 0 combo).
6077 //
6078 // TODO: loadscr should set curdmap, but currently callers do that.
6079 35756 void loadscr(int32_t destdmap, int32_t screen, int32_t ldir, bool origin_screen_overlay, bool no_x80_dir)
6080 {
6081 35756 zapp_reporting_set_tag("screen", screen);
6082
2/2
✓ Branch 0 taken 8915 times.
✓ Branch 1 taken 26841 times.
35756 if (destdmap != -1)
6083 8915 zapp_reporting_set_tag("dmap", destdmap);
6084
6085 35756 int32_t orig_destdmap = destdmap;
6086
2/2
✓ Branch 0 taken 8915 times.
✓ Branch 1 taken 26841 times.
35756 if (destdmap < 0) destdmap = cur_dmap;
6087
6088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35756 times.
35756 if (replay_is_active())
6089 {
6090
1/2
✓ Branch 0 taken 35756 times.
✗ Branch 1 not taken.
35756 if (replay_get_mode() == ReplayMode::ManualTakeover)
6091 replay_stop_manual_takeover();
6092
6093
2/2
✓ Branch 0 taken 26841 times.
✓ Branch 1 taken 8915 times.
35756 if (orig_destdmap != -1)
6094 {
6095
2/2
✓ Branch 0 taken 7842 times.
✓ Branch 1 taken 1073 times.
8915 if (strlen(DMaps[orig_destdmap].name) > 0)
6096 {
6097
1/2
✓ Branch 0 taken 7842 times.
✗ Branch 1 not taken.
7842 replay_step_comment(fmt::format("dmap={} {}", orig_destdmap, DMaps[orig_destdmap].name));
6098 7842 }
6099 else
6100 {
6101
1/2
✓ Branch 0 taken 1073 times.
✗ Branch 1 not taken.
1073 replay_step_comment(fmt::format("dmap={}", orig_destdmap));
6102 }
6103 8915 }
6104 35756 replay_step_comment_loadscr(screen);
6105
6106 // Reset the rngs and frame count so that recording steps can be modified without impacting
6107 // behavior of later screens.
6108 35756 replay_sync_rng();
6109 35756 }
6110
6111
2/2
✓ Branch 0 taken 1704877 times.
✓ Branch 1 taken 35756 times.
1740633 for (auto& state : get_screen_states())
6112 1704877 state.second.triggered_secrets = false;
6113 35756 slopes.clear();
6114 35756 Hero.clear_platform_ffc();
6115 35756 timeExitAllGenscript(GENSCR_ST_CHANGE_SCREEN);
6116 35756 clear_darkroom_bitmaps();
6117 35756 msgscr = nullptr;
6118
6119
2/2
✓ Branch 0 taken 50332123 times.
✓ Branch 1 taken 35756 times.
50367879 for (word x=0; x<animated_combos; x++)
6120 {
6121
2/2
✓ Branch 0 taken 20918733 times.
✓ Branch 1 taken 29413390 times.
50332123 if(combobuf[animated_combo_table4[x][0]].nextcombo!=0)
6122 {
6123 20918733 combobuf[animated_combo_table4[x][0]].aclk = 0;
6124 20918733 }
6125 50332123 }
6126 35756 reset_combo_animations2();
6127 35756 region_is_lit = false;
6128
6129 // Legacy features (combo and ffc overlays) may need the previous origin screens during loading
6130 // of the new ones.
6131 35756 bool origin_ffc_overlay = false;
6132
2/2
✓ Branch 0 taken 34622 times.
✓ Branch 1 taken 1134 times.
35756 if (origin_scr)
6133 {
6134
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 34620 times.
34622 if (!(origin_scr->flags5&fNOFFCARRYOVER))
6135 {
6136 34620 int c = origin_scr->numFFC();
6137
2/2
✓ Branch 0 taken 34476 times.
✓ Branch 1 taken 1035647 times.
1070123 for (int i = 0; i < c; i++)
6138 {
6139
2/2
✓ Branch 0 taken 1035503 times.
✓ Branch 1 taken 144 times.
1035647 if (origin_scr->ffcs[i].flags&ffc_carryover)
6140 {
6141 144 origin_ffc_overlay = true;
6142 144 break;
6143 }
6144 1035503 }
6145 34620 }
6146
6147
3/4
✓ Branch 0 taken 34622 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144 times.
✓ Branch 3 taken 34478 times.
34622 if (origin_screen_overlay || origin_ffc_overlay)
6148 {
6149
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 144 times.
1152 for (int i = 0; i <= 6; i++)
6150 {
6151 1008 mapscr* prev_scr = get_scr_layer(cur_screen, i);
6152
1/2
✓ Branch 0 taken 1008 times.
✗ Branch 1 not taken.
1008 if (prev_scr)
6153 1008 prev_origin_scrs[i] = *prev_scr;
6154 else
6155 prev_origin_scrs[i] = {};
6156 1008 }
6157 144 }
6158 34622 }
6159
6160 // Based on origin_ffc_overlay, some ffc scripts don't get reset. This set starts with all of
6161 // them, but scripts that need their data to persist will be removed.
6162 35756 loadscr_ffc_script_ids_to_remove.clear();
6163
2/2
✓ Branch 0 taken 74526260 times.
✓ Branch 1 taken 35756 times.
74562016 for (auto& key : scriptEngineDatas | std::views::keys)
6164 {
6165
2/2
✓ Branch 0 taken 73407587 times.
✓ Branch 1 taken 1118673 times.
74526260 if (key.first == ScriptType::FFC)
6166 1118673 loadscr_ffc_script_ids_to_remove.insert(key.second);
6167 }
6168
6169 35756 load_region(destdmap, screen);
6170
2/2
✓ Branch 0 taken 903 times.
✓ Branch 1 taken 34853 times.
35756 home_screen = screen >= 0x80 ? hero_screen : cur_screen;
6171 35756 hero_screen = screen;
6172
6173 35756 cpos_clear_all();
6174 35756 FFCore.destroyScriptableObjectsOfType(ScriptType::Screen);
6175 35756 FFCore.clear_combo_scripts();
6176
6177
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 35592 times.
35756 if (is_in_scrolling_region())
6178 {
6179
2/2
✓ Branch 0 taken 20992 times.
✓ Branch 1 taken 164 times.
21156 for (int screen = 0; screen < 128; screen++)
6180 {
6181
2/2
✓ Branch 0 taken 19584 times.
✓ Branch 1 taken 1408 times.
20992 if (is_in_current_region(screen))
6182 {
6183
1/2
✓ Branch 0 taken 1408 times.
✗ Branch 1 not taken.
1408 bool screen_overlay = origin_screen_overlay && screen == cur_screen;
6184
1/2
✓ Branch 0 taken 1408 times.
✗ Branch 1 not taken.
1408 bool ffc_overlay = origin_ffc_overlay && screen == cur_screen;
6185 1408 load_a_screen_and_layers_init(destdmap, screen, ldir, screen_overlay, ffc_overlay);
6186 1408 }
6187 20992 }
6188 164 }
6189 else
6190 {
6191 35592 load_a_screen_and_layers_init(destdmap, screen, ldir, origin_screen_overlay, origin_ffc_overlay);
6192 }
6193
6194 35756 prepare_current_region_handles();
6195
6196
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 35592 times.
35756 if (is_in_scrolling_region())
6197 {
6198
2/2
✓ Branch 0 taken 20992 times.
✓ Branch 1 taken 164 times.
21156 for (int screen = 0; screen < 128; screen++)
6199 {
6200
2/2
✓ Branch 0 taken 19584 times.
✓ Branch 1 taken 1408 times.
20992 if (is_in_current_region(screen))
6201 {
6202 1408 load_a_screen_and_layers_post(destdmap, screen, ldir);
6203 1408 }
6204 20992 }
6205 164 }
6206 else
6207 {
6208 35592 load_a_screen_and_layers_post(destdmap, screen, ldir);
6209 }
6210
6211 // If on a special screen, load the screen the player is currently on (home_screen) into special_warp_return_scr.
6212
2/2
✓ Branch 0 taken 34853 times.
✓ Branch 1 taken 903 times.
35756 if (screen >= 0x80)
6213
2/2
✓ Branch 0 taken 474 times.
✓ Branch 1 taken 429 times.
903 loadscr_old(orig_destdmap, home_screen, no_x80_dir ? -1 : ldir, origin_screen_overlay);
6214
6215 35756 update_slope_comboposes();
6216 35756 cpos_force_update();
6217 35756 trig_trigger_groups();
6218
6219
2/2
✓ Branch 0 taken 1118399 times.
✓ Branch 1 taken 35756 times.
1154155 for (int index : loadscr_ffc_script_ids_to_remove)
6220 {
6221 1118399 FFCore.destroyScriptableObject(ScriptType::FFC, index);
6222 }
6223
6224 // "extended height mode" includes the top 56 pixels as part of the visible mapscr viewport,
6225 // allowing for regions to display 4 more rows of combos (as many as ALTTP does). This part of
6226 // screen is normally reserved for the passive subscreen, but in this mode mapscr combos are drawn below it.
6227 // It is up to the quest designer to make their subscreen be actually transparent.
6228 //
6229 // When not in "extended height mode" (otherwise 56 is 0):
6230 // - playing_field_offset: 56, but changes during earthquakes
6231 // - original_playing_field_offset: always 56
6232 //
6233 // These values are used to adjust where things are drawn on screen to account for the passive subscreen. Examples:
6234 // - yofs of sprites
6235 // - bitmap y offsets in draw_screen
6236 // - drawing offsets for putscr, do_layer
6237 // - drawing offsets for various calls to overtile16 (see bomb weapon explosion)
6238 // - lots more
6239 //
6240 // TODO: consider refactor of yofs, make yofs start as 0 by default and add playing_field_offset at draw time?
6241
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 35614 times.
35756 if (is_extended_height_mode())
6242 {
6243 142 playing_field_offset = 0;
6244 142 original_playing_field_offset = 0;
6245 // A few sprites exist as globals, so we must manually reset them.
6246 142 Hero.yofs = 0;
6247 142 mblock2.yofs = 0;
6248 142 }
6249 else
6250 {
6251 35614 mblock2.yofs = Hero.yofs = playing_field_offset = 56;
6252 35614 original_playing_field_offset = 56;
6253 }
6254 35756 is_any_room_dark = is_any_dark();
6255
6256 35756 game->load_portal();
6257 35756 throwGenScriptEvent(GENSCR_EVENT_CHANGE_SCREEN);
6258
3/4
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 35721 times.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
35756 if (Hero.lift_wpn && get_qr(qr_CARRYABLE_NO_ACROSS_SCREEN))
6259 {
6260 delete Hero.lift_wpn;
6261 Hero.lift_wpn = nullptr;
6262 }
6263
6264 35756 enemy_spawning_has_checked_been_here = false;
6265 35756 markBmap(-1, hero_screen);
6266 35756 Hero.maybe_begin_advanced_maze();
6267 35756 }
6268
6269 // Don't use this directly! Use `loadscr` instead.
6270 903 void loadscr_old(int32_t destdmap, int32_t screen,int32_t ldir,bool overlay)
6271 {
6272
1/2
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
903 int32_t destlvl = DMaps[destdmap < 0 ? cur_dmap : destdmap].level;
6273
6274 903 mapscr previous_scr = *special_warp_return_scr;
6275 903 mapscr* scr = special_warp_return_scr;
6276
1/2
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
903 const mapscr* source = get_canonical_scr(cur_map, screen);
6277
1/2
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
903 *scr = *source;
6278
6279
2/2
✓ Branch 0 taken 5418 times.
✓ Branch 1 taken 903 times.
6321 for (int i = 1; i <= 6; i++)
6280 {
6281
2/2
✓ Branch 0 taken 379 times.
✓ Branch 1 taken 5039 times.
5418 if (scr->layermap[i-1] > 0)
6282
2/4
✓ Branch 0 taken 379 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 379 times.
✗ Branch 3 not taken.
379 special_warp_return_scrs[i] = *get_canonical_scr(scr->layermap[i-1] - 1, scr->layerscreen[i-1]);
6283 else
6284 5039 special_warp_return_scrs[i] = {};
6285 5418 }
6286
6287 903 scr->valid |= mVALID; //layer 0 is always valid
6288
6289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 903 times.
903 if ( source->script > 0 )
6290 {
6291 scr->script = source->script;
6292 for ( int32_t q = 0; q < 8; q++ )
6293 {
6294 scr->screeninitd[q] = source->screeninitd[q];
6295 }
6296 FFCore.reset_script_engine_data(ScriptType::Screen, screen);
6297 }
6298 else
6299 {
6300 903 scr->script = 0;
6301 }
6302
6303
1/2
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
903 if(overlay)
6304 {
6305 for(int32_t c=0; c< 176; ++c)
6306 {
6307 if(scr->data[c]==0)
6308 {
6309 scr->data[c]=previous_scr.data[c];
6310 scr->sflag[c]=previous_scr.sflag[c];
6311 scr->cset[c]=previous_scr.cset[c];
6312 }
6313 }
6314
6315 for(int32_t i=0; i<6; i++)
6316 {
6317 if(previous_scr.layermap[i]>0 && scr->layermap[i]>0)
6318 {
6319 int32_t lm = (scr->layermap[i]-1)*MAPSCRS+scr->layerscreen[i];
6320 int32_t fm = (previous_scr.layermap[i]-1)*MAPSCRS+previous_scr.layerscreen[i];
6321
6322 for(int32_t c=0; c< 176; ++c)
6323 {
6324 if(TheMaps[lm].data[c]==0)
6325 {
6326 TheMaps[lm].data[c] = TheMaps[fm].data[c];
6327 TheMaps[lm].sflag[c] = TheMaps[fm].sflag[c];
6328 TheMaps[lm].cset[c] = TheMaps[fm].cset[c];
6329 }
6330 }
6331 }
6332 }
6333 }
6334
6335
1/2
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
29768 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
6336
1/2
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
903 int c = scr->numFFC();
6337
2/2
✓ Branch 0 taken 903 times.
✓ Branch 1 taken 28865 times.
29768 for (word i = 0; i < c; i++)
6338 {
6339 28865 scr->ffcs[i].screen_spawned = screen;
6340
1/2
✓ Branch 0 taken 28865 times.
✗ Branch 1 not taken.
28865 scr->ffcs[i].x += offx;
6341
1/2
✓ Branch 0 taken 28865 times.
✗ Branch 1 not taken.
28865 scr->ffcs[i].y += offy;
6342 28865 }
6343
6344 903 int mi = mapind(cur_map, screen);
6345
6346 // Apply perm secrets, if applicable.
6347
3/4
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 532 times.
✓ Branch 3 taken 371 times.
903 if(canPermSecret(destdmap,screen))
6348 {
6349
3/4
✓ Branch 0 taken 532 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 202 times.
✓ Branch 3 taken 330 times.
532 if(game->maps[mi]&mSECRET) // if special stuff done before
6350 {
6351
1/2
✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
202 reveal_hidden_stairs(scr, screen, false);
6352
6353
1/2
✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
202 log_trigger_secret_reason(TriggerSource::SecretsScreenState);
6354
1/2
✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
202 get_screen_state(special_warp_return_scr->screen).triggered_secrets = true;
6355 202 bool do_replay_comment = true;
6356 202 bool from_active_screen = false;
6357
2/4
✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 202 times.
✗ Branch 3 not taken.
202 trigger_secrets_for_screen_internal(create_screen_handles(special_warp_return_scr), from_active_screen, false, -1, do_replay_comment);
6358 202 }
6359
2/4
✓ Branch 0 taken 532 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 532 times.
✗ Branch 3 not taken.
532 if(game->maps[mi]&mLIGHTBEAM) // if special stuff done before
6360 {
6361 for (int layer = 0; layer <= 6; layer++)
6362 {
6363 mapscr* tscr = &special_warp_return_scrs[layer];
6364 for (int pos = 0; pos < 176; pos++)
6365 {
6366 newcombo const* cmb = &combobuf[tscr->data[pos]];
6367 if(cmb->type == cLIGHTTARGET)
6368 {
6369 if(!(cmb->usrflags&cflag1)) //Unlit version
6370 {
6371 tscr->data[pos] += 1;
6372 }
6373 }
6374 }
6375 }
6376 }
6377 532 }
6378
6379 screen_handles_t screen_handles;
6380
2/2
✓ Branch 0 taken 903 times.
✓ Branch 1 taken 6321 times.
7224 for (int i = 0; i <= 6; i++)
6381
3/4
✓ Branch 0 taken 6321 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1281 times.
✓ Branch 3 taken 5040 times.
6321 screen_handles[i] = {scr, special_warp_return_scrs[i].is_valid() ? &special_warp_return_scrs[i] : nullptr, screen, i};
6382
6383
2/4
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 903 times.
✗ Branch 3 not taken.
903 toggle_switches(game->lvlswitches[destlvl], true, screen_handles);
6384
1/2
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
903 toggle_gswitches_load(screen_handles);
6385
6386
3/4
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 898 times.
903 if(game->maps[mi]&mLOCKBLOCK) // if special stuff done before
6387 {
6388
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 remove_lockblocks(screen_handles);
6389 5 }
6390
6391
3/4
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 902 times.
903 if(game->maps[mi]&mBOSSLOCKBLOCK) // if special stuff done before
6392 {
6393
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 remove_bosslockblocks(screen_handles);
6394 1 }
6395
6396
2/4
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 903 times.
903 if(game->maps[mi]&mCHEST) // if special stuff done before
6397 {
6398 remove_chests(screen_handles);
6399 }
6400
6401
2/4
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 903 times.
903 if(game->maps[mi]&mLOCKEDCHEST) // if special stuff done before
6402 {
6403 remove_lockedchests(screen_handles);
6404 }
6405
6406
2/4
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 903 times.
903 if(game->maps[mi]&mBOSSCHEST) // if special stuff done before
6407 {
6408 remove_bosschests(screen_handles);
6409 }
6410
6411
1/2
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
903 clear_xdoors(screen_handles, true);
6412
1/2
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
903 clear_xstatecombos(screen_handles, true);
6413
6414 // check doors
6415
3/4
✓ Branch 0 taken 903 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 371 times.
✓ Branch 3 taken 532 times.
903 if (isdungeon(destdmap, screen))
6416 {
6417
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 371 times.
1855 for(int32_t i=0; i<4; i++)
6418 {
6419 1484 int32_t door=scr->door[i];
6420
6421
4/4
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 89 times.
✓ Branch 3 taken 1295 times.
1484 switch(door)
6422 {
6423 case d1WAYSHUTTER:
6424 case dSHUTTER:
6425
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1295 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1295 if ((ldir^1)==i && screen == home_screen)
6426 {
6427 scr->door[i]=dOPENSHUTTER;
6428 }
6429
6430
2/2
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 1190 times.
1295 get_screen_state(screen).open_doors = -4;
6431 105 break;
6432
6433 case dLOCKED:
6434
3/4
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 11 times.
91 if(game->maps[mi]&(1<<i))
6435 {
6436 80 scr->door[i]=dUNLOCKED;
6437 80 }
6438
6439 91 break;
6440
6441 case dBOSS:
6442
3/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 4 times.
9 if(game->maps[mi]&(1<<i))
6443 {
6444 5 scr->door[i]=dOPENBOSS;
6445 5 }
6446
6447 9 break;
6448
6449 case dBOMB:
6450
3/4
✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✓ Branch 3 taken 38 times.
89 if(game->maps[mi]&(1<<i))
6451 {
6452 51 scr->door[i]=dBOMBED;
6453 51 }
6454
6455 89 break;
6456 }
6457
6458
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 1190 times.
294 update_door(scr, i, scr->door[i]);
6459
6460
4/4
✓ Branch 0 taken 1390 times.
✓ Branch 1 taken 94 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 1379 times.
1484 if(door==dSHUTTER||door==d1WAYSHUTTER)
6461 {
6462 105 scr->door[i]=door;
6463 105 }
6464 1484 }
6465 371 }
6466
6467
2/2
✓ Branch 0 taken 6895 times.
✓ Branch 1 taken 733 times.
7224 for(int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6468 {
6469
4/4
✓ Branch 0 taken 5418 times.
✓ Branch 1 taken 1477 times.
✓ Branch 2 taken 2759 times.
✓ Branch 3 taken 2659 times.
6895 if (j<0 || scr->layermap[j] > 0)
6470 {
6471
4/4
✓ Branch 0 taken 903 times.
✓ Branch 1 taken 379 times.
✓ Branch 2 taken 378 times.
✓ Branch 3 taken 1 times.
4236 mapscr *layerscreen= (j<0 ? scr : special_warp_return_scrs[j+1].valid ? &special_warp_return_scrs[j+1] :
6472 1 &TheMaps[(scr->layermap[j]-1)*MAPSCRS]+scr->layerscreen[j]);
6473
6474
2/2
✓ Branch 0 taken 223252 times.
✓ Branch 1 taken 3662 times.
226914 for(int32_t i=0; i<176; ++i)
6475 {
6476 223252 int32_t c=layerscreen->data[i];
6477
6478 // New screen flag: Cycle Combos At Screen Init
6479
5/8
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 223246 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 2380 times.
✓ Branch 7 taken 2380 times.
223252 if(combobuf[c].nextcombo != 0 && (scr->flags3 & fCYCLEONINIT) && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6480 {
6481 2380 int32_t r = 0;
6482
6483
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2380 while(combobuf[c].can_cycle() && r++ < 10)
6484 {
6485 newcombo const& cmb = combobuf[c];
6486 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6487 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6488 layerscreen->data[i] = cid;
6489 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6490 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6491 c = layerscreen->data[i];
6492 }
6493 }
6494 225632 }
6495 3662 }
6496 6321 }
6497 5493 }
6498
6499 // Load screen (and layers). Unlike loadscr, this doesn't load to the global temporary_screens, but
6500 // instead returns an array of mapscr.
6501 // Used to draw/save the map.
6502 45680 std::array<mapscr, 7> loadscr2(int32_t screen)
6503 {
6504 45680 std::array<mapscr, 7> scrs;
6505 45680 mapscr* scr = &scrs[0];
6506
6507
2/2
✓ Branch 0 taken 64716181 times.
✓ Branch 1 taken 45680 times.
64761861 for(word x=0; x<animated_combos; x++)
6508 {
6509
2/2
✓ Branch 0 taken 31963685 times.
✓ Branch 1 taken 32752496 times.
64716181 if(combobuf[animated_combo_table4[x][0]].nextcombo!=0)
6510 {
6511 32752496 combobuf[animated_combo_table4[x][0]].aclk=0;
6512 32752496 }
6513 64716181 }
6514
6515
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 const mapscr* source = get_canonical_scr(cur_map, screen);
6516
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if (!source->is_valid())
6517 {
6518 scrs[0].valid = 0;
6519 return scrs;
6520 }
6521
6522
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 *scr = *get_canonical_scr(cur_map, screen);
6523
2/2
✓ Branch 0 taken 274080 times.
✓ Branch 1 taken 45680 times.
319760 for (int i = 1; i <= 6; i++)
6524 {
6525
2/2
✓ Branch 0 taken 64814 times.
✓ Branch 1 taken 209266 times.
274080 if (scr->layermap[i-1] > 0)
6526
2/4
✓ Branch 0 taken 64814 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64814 times.
✗ Branch 3 not taken.
64814 scrs[i] = *get_canonical_scr(scr->layermap[i-1] - 1, scr->layerscreen[i-1]);
6527 else
6528 209266 scrs[i] = {};
6529 274080 }
6530
6531 screen_handles_t screen_handles;
6532
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 319760 times.
365440 for (int i = 0; i < 7; i++)
6533
3/4
✓ Branch 0 taken 319760 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103790 times.
✓ Branch 3 taken 215970 times.
319760 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
6534
6535 45680 int mi = mapind(cur_map, screen);
6536
6537
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45626 times.
✓ Branch 3 taken 54 times.
45680 if(canPermSecret(-1,screen))
6538 {
6539
3/4
✓ Branch 0 taken 45626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5730 times.
✓ Branch 3 taken 39896 times.
45626 if(game->maps[mi]&mSECRET) // if special stuff done before
6540 {
6541
1/2
✓ Branch 0 taken 5730 times.
✗ Branch 1 not taken.
5730 reveal_hidden_stairs(scr, screen, false);
6542 5730 bool from_active_screen = false;
6543 5730 bool do_replay_comment = true;
6544
1/2
✓ Branch 0 taken 5730 times.
✗ Branch 1 not taken.
5730 trigger_secrets_for_screen_internal(screen_handles, from_active_screen, false, -1, do_replay_comment);
6545 5730 }
6546
3/4
✓ Branch 0 taken 45626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45609 times.
✓ Branch 3 taken 17 times.
45626 if(game->maps[mi]&mLIGHTBEAM) // if special stuff done before
6547 {
6548
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 17 times.
136 for (int layer = 0; layer <= 6; layer++)
6549 {
6550 119 mapscr* tscr = &scrs[layer];
6551
2/2
✓ Branch 0 taken 20944 times.
✓ Branch 1 taken 119 times.
21063 for (int pos = 0; pos < 176; pos++)
6552 {
6553 20944 newcombo const* cmb = &combobuf[tscr->data[pos]];
6554
2/2
✓ Branch 0 taken 20927 times.
✓ Branch 1 taken 17 times.
20944 if(cmb->type == cLIGHTTARGET)
6555 {
6556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if(!(cmb->usrflags&cflag1)) //Unlit version
6557 {
6558 17 tscr->data[pos] += 1;
6559 17 }
6560 17 }
6561 20944 }
6562 119 }
6563 17 }
6564 45626 }
6565
6566
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 233 times.
✓ Branch 3 taken 45447 times.
45680 if(game->maps[mi]&mLOCKBLOCK) // if special stuff done before
6567 {
6568
1/2
✓ Branch 0 taken 233 times.
✗ Branch 1 not taken.
233 remove_lockblocks(screen_handles);
6569 233 }
6570
6571
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 45679 times.
45680 if(game->maps[mi]&mBOSSLOCKBLOCK) // if special stuff done before
6572 {
6573
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 remove_bosslockblocks(screen_handles);
6574 1 }
6575
6576
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 101 times.
✓ Branch 3 taken 45579 times.
45680 if(game->maps[mi]&mCHEST) // if special stuff done before
6577 {
6578
1/2
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
101 remove_chests(screen_handles);
6579 101 }
6580
6581
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 45656 times.
45680 if(game->maps[mi]&mLOCKEDCHEST) // if special stuff done before
6582 {
6583
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 remove_lockedchests(screen_handles);
6584 24 }
6585
6586
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45680 times.
45680 if(game->maps[mi]&mBOSSCHEST) // if special stuff done before
6587 {
6588 remove_bosschests(screen_handles);
6589 }
6590
6591
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 clear_xdoors(screen_handles);
6592
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 clear_xstatecombos(screen_handles);
6593
6594 // check doors
6595
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 45626 times.
45680 if (isdungeon(screen))
6596 {
6597
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 54 times.
270 for(int32_t i=0; i<4; i++)
6598 {
6599 216 int32_t door=scr->door[i];
6600 216 bool putit=true;
6601
6602
4/5
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 61 times.
✓ Branch 4 taken 139 times.
216 switch(door)
6603 {
6604 case d1WAYSHUTTER:
6605 case dSHUTTER:
6606 61 break;
6607
6608 case dLOCKED:
6609
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if(game->maps[mi]&(1<<i))
6610 {
6611 12 scr->door[i]=dUNLOCKED;
6612 12 }
6613
6614 12 break;
6615
6616 case dBOSS:
6617
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if(game->maps[mi]&(1<<i))
6618 {
6619 scr->door[i]=dOPENBOSS;
6620 }
6621
6622 4 break;
6623
6624 case dBOMB:
6625 if(game->maps[mi]&(1<<i))
6626 {
6627 scr->door[i]=dBOMBED;
6628 }
6629
6630 break;
6631 }
6632
6633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 if(putit)
6634 {
6635
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
216 putdoor(scr, scrollbuf, i, scr->door[i], false);
6636 216 }
6637
6638
3/4
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 61 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 155 times.
216 if(door==dSHUTTER||door==d1WAYSHUTTER)
6639 {
6640 61 scr->door[i]=door;
6641 61 }
6642 216 }
6643 54 }
6644
6645
2/2
✓ Branch 0 taken 319760 times.
✓ Branch 1 taken 45680 times.
365440 for(int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6646 {
6647
4/4
✓ Branch 0 taken 274080 times.
✓ Branch 1 taken 45680 times.
✓ Branch 2 taken 64814 times.
✓ Branch 3 taken 209266 times.
319760 if (j < 0 || scr->layermap[j] > 0)
6648 {
6649
2/2
✓ Branch 0 taken 64814 times.
✓ Branch 1 taken 45680 times.
110494 mapscr *layerscreen= (j<0 ? scr
6650 64814 : &(TheMaps[(scr->layermap[j]-1)*MAPSCRS+scr->layerscreen[j]]));
6651
6652
2/2
✓ Branch 0 taken 19446944 times.
✓ Branch 1 taken 110494 times.
19557438 for(int32_t i=0; i<176; ++i)
6653 {
6654 19446944 int32_t c=layerscreen->data[i];
6655
6656 // New screen flag: Cycle Combos At Screen Init
6657
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 19446944 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
19446944 if((scr->flags3 & fCYCLEONINIT) && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6658 {
6659 int32_t r = 0;
6660
6661 while(combobuf[c].can_cycle() && r++ < 10)
6662 {
6663 newcombo const& cmb = combobuf[c];
6664 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6665 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6666 layerscreen->data[i] = cid;
6667 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6668 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6669 c = layerscreen->data[i];
6670 }
6671 }
6672 19446944 }
6673 110494 }
6674 319760 }
6675
6676 45680 return scrs;
6677
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 }
6678
6679 18939978 void putscr(mapscr* scr, BITMAP* dest, int32_t x, int32_t y)
6680 {
6681 // This is a bogus value while screenscrolling == true, but that's ok
6682 // because it is only used to calculate the rpos, and during screenscrolling
6683 // only the modulus to get pos (draw_cmb_pos does RPOS_TO_POS) is needed, which
6684 // is always the same no matter the value of scr.
6685 18939978 int screen = get_screen_for_world_xy(x, y);
6686
6687 18939978 x -= viewport.x;
6688 18939978 y -= viewport.y;
6689
6690
3/6
✓ Branch 0 taken 18939978 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18939978 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18939978 times.
18939978 if (!scr->is_valid()||!show_layers[0]||scr->hidelayers & 1)
6691 {
6692 rectfill(dest,x,y,x+255,y+175,0);
6693 return;
6694 }
6695
6696 37751046 bool over = XOR(scr->flags7&fLAYER2BG,DMaps[cur_dmap].flags&dmfLAYER2BG)
6697
2/2
✓ Branch 0 taken 128910 times.
✓ Branch 1 taken 18811068 times.
18939978 || XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG);
6698
6699 int start_x, end_x, start_y, end_y;
6700 18939978 get_bounds_for_draw_cmb_calls(dest, x, y, start_x, end_x, start_y, end_y);
6701
2/2
✓ Branch 0 taken 18939978 times.
✓ Branch 1 taken 201744404 times.
220684382 for (int cy = start_y; cy < end_y; cy++)
6702 {
6703
2/2
✓ Branch 0 taken 3063548135 times.
✓ Branch 1 taken 201744404 times.
3265292539 for (int cx = start_x; cx < end_x; cx++)
6704 {
6705 3063548135 int i = cx + cy*16;
6706
2/2
✓ Branch 0 taken 355787803 times.
✓ Branch 1 taken 2707760332 times.
3063548135 auto rpos = screenscrolling ? rpos_t::None : POS_TO_RPOS(i, screen);
6707 3063548135 draw_cmb_pos(dest, x + cx*16, y + cy*16, rpos, scr->data[i], scr->cset[i], 0, over, false);
6708 3063548135 }
6709 201744404 }
6710 18939978 }
6711
6712 15478836 static void putscrdoors(const nearby_screens_t& nearby_screens, BITMAP *dest, int32_t x, int32_t y)
6713 {
6714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15478836 times.
15478836 if (!show_layers[0])
6715 {
6716 return;
6717 }
6718
6719 15478836 x -= viewport.x;
6720 15478836 y -= viewport.y;
6721
6722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15478836 times.
31093990 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
6723 15615154 mapscr* scr = screen_handles[0].base_scr;
6724
1/2
✓ Branch 0 taken 15615154 times.
✗ Branch 1 not taken.
15615154 if (!scr->is_valid())
6725 return;
6726
6727
2/2
✓ Branch 0 taken 120365 times.
✓ Branch 1 taken 15494789 times.
15615154 if(scr->door[0]==dBOMBED)
6728 {
6729 120365 over_door(scr, dest, 39, up, offx+x, offy+y);
6730 120365 }
6731
6732
2/2
✓ Branch 0 taken 140024 times.
✓ Branch 1 taken 15475130 times.
15615154 if(scr->door[1]==dBOMBED)
6733 {
6734 140024 over_door(scr, dest, 135, down, offx+x, offy+y);
6735 140024 }
6736
6737
2/2
✓ Branch 0 taken 155862 times.
✓ Branch 1 taken 15459292 times.
15615154 if(scr->door[2]==dBOMBED)
6738 {
6739 155862 over_door(scr, dest, 66, left, offx+x, offy+y);
6740 155862 }
6741
6742
2/2
✓ Branch 0 taken 132289 times.
✓ Branch 1 taken 15482865 times.
15615154 if(scr->door[3]==dBOMBED)
6743 {
6744 132289 over_door(scr, dest, 77, right, offx+x, offy+y);
6745 132289 }
6746 15615154 });
6747 15478836 }
6748
6749 3324824 void putscrdoors(mapscr* scr, BITMAP *dest, int32_t x, int32_t y)
6750 {
6751
2/4
✓ Branch 0 taken 3324824 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3324824 times.
✗ Branch 3 not taken.
3324824 if (!scr->is_valid() || !show_layers[0])
6752 return;
6753
6754 3324824 x -= viewport.x;
6755 3324824 y -= viewport.y;
6756
6757
2/2
✓ Branch 0 taken 36241 times.
✓ Branch 1 taken 3288583 times.
3324824 if(scr->door[0]==dBOMBED)
6758 {
6759 36241 over_door(scr,dest,39,up,x,y);
6760 36241 }
6761
6762
2/2
✓ Branch 0 taken 35339 times.
✓ Branch 1 taken 3289485 times.
3324824 if(scr->door[1]==dBOMBED)
6763 {
6764 35339 over_door(scr,dest,135,down,x,y);
6765 35339 }
6766
6767
2/2
✓ Branch 0 taken 40440 times.
✓ Branch 1 taken 3284384 times.
3324824 if(scr->door[2]==dBOMBED)
6768 {
6769 40440 over_door(scr,dest,66,left,x,y);
6770 40440 }
6771
6772
2/2
✓ Branch 0 taken 37063 times.
✓ Branch 1 taken 3287761 times.
3324824 if(scr->door[3]==dBOMBED)
6773 {
6774 37063 over_door(scr,dest,77,right,x,y);
6775 37063 }
6776 3324824 }
6777 231457785 static inline bool onSwitch(newcombo const& cmb, zfix const& switchblockstate)
6778 {
6779
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 231457785 times.
✓ Branch 2 taken 231436890 times.
✓ Branch 3 taken 20895 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 20895 times.
231457785 return (switchblockstate < 0 || (cmb.attributes[2]>0 && (zslongToFix(cmb.attributes[2]) - zslongToFix(zc_max(cmb.attributes[3], 0))) <=switchblockstate));
6780 }
6781 55745693 bool _walkflag(zfix_round zx,zfix_round zy,int32_t cnt)
6782 {
6783 55745693 return _walkflag(zx,zy,cnt,0_zf);
6784 }
6785
6786 132174910 bool _walkflag_new(const mapscr* s0, const mapscr* s1, const mapscr* s2, zfix_round zx, zfix_round zy, zfix const& switchblockstate, bool is_temp_screens)
6787 {
6788 132174910 int x = zx.getRound(), y = zy.getRound();
6789 132174910 int pos = COMBOPOS(x % 256, y % 176);
6790 132174910 const newcombo& c = combobuf[s0->data[pos]];
6791 132174910 const newcombo& c1 = combobuf[s1->data[pos]];
6792 132174910 const newcombo& c2 = combobuf[s2->data[pos]];
6793
4/4
✓ Branch 0 taken 130193387 times.
✓ Branch 1 taken 1981523 times.
✓ Branch 2 taken 130183927 times.
✓ Branch 3 taken 9460 times.
264552108 bool dried = (((iswater_type(c.type)) || (iswater_type(c1.type)) ||
6794
4/4
✓ Branch 0 taken 101153 times.
✓ Branch 1 taken 130285062 times.
✓ Branch 2 taken 2087891 times.
✓ Branch 3 taken 4245 times.
132174910 (iswater_type(c2.type))) && DRIEDLAKE);
6795 132377198 int32_t b=1;
6796
2/2
✓ Branch 0 taken 65256005 times.
✓ Branch 1 taken 67121193 times.
132377198 if(x&8) b<<=2;
6797
2/2
✓ Branch 0 taken 61843959 times.
✓ Branch 1 taken 70533239 times.
132377198 if(y&8) b<<=1;
6798
6799 132377198 int32_t cwalkflag = c.walk;
6800
3/8
✓ Branch 0 taken 132276054 times.
✓ Branch 1 taken 101144 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 132276054 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
132377198 if(is_temp_screens && onSwitch(c,switchblockstate) && c.type == cCSWITCHBLOCK && c.usrflags&cflag9) cwalkflag &= (c.walk>>4)^0xF;
6801
8/10
✓ Branch 0 taken 50572 times.
✓ Branch 1 taken 132326626 times.
✓ Branch 2 taken 2082667 times.
✓ Branch 3 taken 2032095 times.
✓ Branch 4 taken 2082667 times.
✓ Branch 5 taken 132276054 times.
✓ Branch 6 taken 2082667 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2082667 times.
✗ Branch 9 not taken.
132377198 else if ((c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) || (iswater_type(c.type) && ((c.walk>>4)&b) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)))) cwalkflag = 0;
6802
2/2
✓ Branch 0 taken 63045535 times.
✓ Branch 1 taken 69230519 times.
132276054 if (s1 != s0)
6803 {
6804
5/8
✓ Branch 0 taken 69230519 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1980 times.
✓ Branch 3 taken 69228539 times.
✓ Branch 4 taken 1980 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1980 times.
69230519 if(is_temp_screens && onSwitch(c1,switchblockstate) && c1.type == cCSWITCHBLOCK && c1.usrflags&cflag9) cwalkflag &= (c1.walk>>4)^0xF;
6805
4/10
✓ Branch 0 taken 11729 times.
✓ Branch 1 taken 69216810 times.
✓ Branch 2 taken 11729 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11729 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
69228539 else if ((iswater_type(c1.type) && ((c1.walk>>4)&b) && get_qr(qr_WATER_ON_LAYER_1) && !((c1.usrflags&cflag3) || (c1.usrflags&cflag4)))) cwalkflag &= c1.walk;
6806
2/2
✓ Branch 0 taken 62906 times.
✓ Branch 1 taken 69165633 times.
69228539 else if (c1.type == cBRIDGE)
6807 {
6808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62906 times.
62906 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
6809 {
6810 62906 int efflag = (c1.walk & 0xF0)>>4;
6811 62906 int newsolid = (c1.walk & 0xF);
6812 62906 cwalkflag = ((newsolid | cwalkflag) & (~efflag)) | (newsolid & efflag);
6813 62906 }
6814 else cwalkflag &= c1.walk;
6815 62906 }
6816
3/8
✓ Branch 0 taken 11729 times.
✓ Branch 1 taken 69153904 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11729 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
69165633 else if ((iswater_type(c1.type) && get_qr(qr_WATER_ON_LAYER_1) && ((c1.usrflags&cflag3) || (c1.usrflags&cflag4)) && ((c1.walk>>4)&b))) cwalkflag = 0;
6817 69165633 else cwalkflag |= c1.walk;
6818 69230519 }
6819
2/2
✓ Branch 0 taken 102324842 times.
✓ Branch 1 taken 29951212 times.
132276054 if (s2 != s0)
6820 {
6821
2/8
✓ Branch 0 taken 29951212 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 29951212 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
29951212 if(is_temp_screens && onSwitch(c2,switchblockstate) && c2.type == cCSWITCHBLOCK && c2.usrflags&cflag9) cwalkflag &= (c2.walk>>4)^0xF;
6822
4/10
✓ Branch 0 taken 2154 times.
✓ Branch 1 taken 29949058 times.
✓ Branch 2 taken 2154 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2154 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
29951212 else if ((iswater_type(c2.type) && ((c2.walk>>4)&b) && get_qr(qr_WATER_ON_LAYER_2) && !((c2.usrflags&cflag3) || (c2.usrflags&cflag4)))) cwalkflag &= c2.walk;
6823
2/2
✓ Branch 0 taken 7790 times.
✓ Branch 1 taken 29943422 times.
29951212 else if (c2.type == cBRIDGE)
6824 {
6825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7790 times.
7790 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
6826 {
6827 7790 int efflag = (c2.walk & 0xF0)>>4;
6828 7790 int newsolid = (c2.walk & 0xF);
6829 7790 cwalkflag = ((newsolid | cwalkflag) & (~efflag)) | (newsolid & efflag);
6830 7790 }
6831 else cwalkflag &= c2.walk;
6832 7790 }
6833
3/8
✓ Branch 0 taken 2154 times.
✓ Branch 1 taken 29941268 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2154 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
29943422 else if ((iswater_type(c2.type) && get_qr(qr_WATER_ON_LAYER_2) && ((c2.usrflags&cflag3) || (c2.usrflags&cflag4))) && ((c2.walk>>4)&b)) cwalkflag = 0;
6834 29943422 else cwalkflag |= c2.walk;
6835 29951212 }
6836
6837
4/4
✓ Branch 0 taken 29492512 times.
✓ Branch 1 taken 102783542 times.
✓ Branch 2 taken 948 times.
✓ Branch 3 taken 29491564 times.
132276054 if((cwalkflag&b) && !dried)
6838 29491564 return true;
6839
6840
3/4
✓ Branch 0 taken 102784490 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 102768079 times.
✓ Branch 3 taken 16411 times.
102784490 if (is_temp_screens && collide_object(zx, zy, 0.0001_zf, 0.0001_zf)) return true;
6841
6842 102768079 return false;
6843 132276054 }
6844
6845 // Returns true if the combo at viewport position x,y is solid. Looks at a combo's quadrant walkablity flags.
6846 132276054 static bool _walkflag_new(zfix_round zx, zfix_round zy, zfix const& switchblockstate)
6847 {
6848 132276054 int x = zx.getRound(), y = zy.getRound();
6849 132276054 mapscr* s0 = get_scr_for_world_xy_layer(x, y, 0);
6850 132276054 mapscr* s1 = get_scr_for_world_xy_layer(x, y, 1);
6851 132276054 mapscr* s2 = get_scr_for_world_xy_layer(x, y, 2);
6852
2/2
✓ Branch 0 taken 63045535 times.
✓ Branch 1 taken 69230519 times.
132276054 if (!s1->valid) s1 = s0;
6853
2/2
✓ Branch 0 taken 102324842 times.
✓ Branch 1 taken 29951212 times.
132276054 if (!s2->valid) s2 = s0;
6854 132276054 return _walkflag_new(s0, s1, s2, zx, zy, switchblockstate, true);
6855 }
6856
6857 128089194 bool _walkflag(zfix_round x,zfix_round y,int32_t cnt,zfix const& switchblockstate)
6858 {
6859 128089194 int max_x = world_w;
6860 128089194 int max_y = world_h;
6861
2/2
✓ Branch 0 taken 68533189 times.
✓ Branch 1 taken 59556005 times.
128089194 if (!get_qr(qr_LTTPWALK))
6862 {
6863 59556005 max_x -= 7;
6864 59556005 max_y -= 7;
6865 59556005 }
6866
4/4
✓ Branch 0 taken 127818374 times.
✓ Branch 1 taken 270820 times.
✓ Branch 2 taken 83268 times.
✓ Branch 3 taken 127735106 times.
128089194 if (x < 0 || y < 0) return false;
6867
2/2
✓ Branch 0 taken 322009 times.
✓ Branch 1 taken 127413097 times.
127735106 if (x >= max_x) return false;
6868
3/4
✓ Branch 0 taken 538913 times.
✓ Branch 1 taken 126874184 times.
✓ Branch 2 taken 538913 times.
✗ Branch 3 not taken.
127413097 if (x >= max_x - 8 && cnt == 2) return false;
6869
2/2
✓ Branch 0 taken 126864399 times.
✓ Branch 1 taken 548698 times.
127413097 if (y >= max_y) return false;
6870
6871
4/4
✓ Branch 0 taken 29390124 times.
✓ Branch 1 taken 97474275 times.
✓ Branch 2 taken 92062620 times.
✓ Branch 3 taken 5411655 times.
126864399 return _walkflag_new(x, y, switchblockstate) || (cnt != 1 && _walkflag_new(x + 8, y, switchblockstate));
6872 128089194 }
6873
6874 98535825 static bool effectflag(int32_t x, int32_t y, int32_t layer)
6875 {
6876 98535825 mapscr* s0 = get_scr_for_world_xy(x, y);
6877 98535825 mapscr* s1 = get_scr_for_world_xy_layer(x, y, 1);
6878 98535825 mapscr* s2 = get_scr_for_world_xy_layer(x, y, 2);
6879
2/2
✓ Branch 0 taken 51141191 times.
✓ Branch 1 taken 47394634 times.
98535825 if (!s1->valid) s1 = s0;
6880
2/2
✓ Branch 0 taken 17705260 times.
✓ Branch 1 taken 80830565 times.
98535825 if (!s2->valid) s2 = s0;
6881
6882 98535825 int pos = COMBOPOS(x % 256, y % 176);
6883 98535825 const newcombo& c = combobuf[s0->data[pos]];
6884 98535825 const newcombo& c1 = combobuf[s1->data[pos]];
6885 98535825 const newcombo& c2 = combobuf[s2->data[pos]];
6886
4/4
✓ Branch 0 taken 97608781 times.
✓ Branch 1 taken 927044 times.
✓ Branch 2 taken 97607415 times.
✓ Branch 3 taken 1366 times.
197071650 bool dried = (((iswater_type(c.type)) || (iswater_type(c1.type)) ||
6887
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 97607415 times.
✓ Branch 2 taken 926574 times.
✓ Branch 3 taken 1836 times.
98535825 (iswater_type(c2.type))) && DRIEDLAKE);
6888 98535825 int32_t b=1;
6889
2/2
✓ Branch 0 taken 49569134 times.
✓ Branch 1 taken 48966691 times.
98535825 if(x&8) b<<=2;
6890
2/2
✓ Branch 0 taken 41540070 times.
✓ Branch 1 taken 56995755 times.
98535825 if(y&8) b<<=1;
6891
6892 98535825 int32_t cwalkflag = (c.walk>>4);
6893
2/2
✓ Branch 0 taken 75943070 times.
✓ Branch 1 taken 22592755 times.
98535825 if (layer == 0) cwalkflag = (c1.walk>>4);
6894
2/2
✓ Branch 0 taken 75944510 times.
✓ Branch 1 taken 22591315 times.
98535825 if (layer == 1) cwalkflag = (c2.walk>>4);
6895 //if (c.type == cBRIDGE || (iswater_type(c.type) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)))) cwalkflag = 0;
6896
4/4
✓ Branch 0 taken 51141191 times.
✓ Branch 1 taken 47394634 times.
✓ Branch 2 taken 22338370 times.
✓ Branch 3 taken 28802821 times.
98535825 if (s1 != s0 && layer < 0)
6897 {
6898
2/2
✓ Branch 0 taken 22324964 times.
✓ Branch 1 taken 13406 times.
22338370 if (c1.type == cBRIDGE) cwalkflag &= (~(c1.walk>>4));
6899 22338370 }
6900
4/4
✓ Branch 0 taken 17705260 times.
✓ Branch 1 taken 80830565 times.
✓ Branch 2 taken 13127339 times.
✓ Branch 3 taken 4577921 times.
98535825 if (s2 != s0 && layer < 1)
6901 {
6902
2/2
✓ Branch 0 taken 13119763 times.
✓ Branch 1 taken 7576 times.
13127339 if (c2.type == cBRIDGE) cwalkflag &= (~(c2.walk>>4));
6903 13127339 }
6904
6905
2/2
✓ Branch 0 taken 98374855 times.
✓ Branch 1 taken 160970 times.
98535825 return (cwalkflag&b) ? !dried : false;
6906 }
6907
6908 98909701 bool _effectflag(int32_t x,int32_t y,int32_t cnt, int32_t layer, bool notLink)
6909 {
6910 DCHECK(cnt == 0 || cnt == 1);
6911 98909701 int max_x = world_w;
6912 98909701 int max_y = world_h;
6913
3/4
✓ Branch 0 taken 45172629 times.
✓ Branch 1 taken 53737072 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45172629 times.
98909701 if (!get_qr(qr_LTTPWALK) && !notLink)
6914 {
6915 45172629 max_x -= 7;
6916 45172629 max_y -= 7;
6917 45172629 }
6918
4/4
✓ Branch 0 taken 98908948 times.
✓ Branch 1 taken 753 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 98908756 times.
98909701 if (x < 0 || y < 0) return false;
6919
2/2
✓ Branch 0 taken 818 times.
✓ Branch 1 taken 98907938 times.
98908756 if (x >= max_x) return false;
6920
3/4
✓ Branch 0 taken 519842 times.
✓ Branch 1 taken 98388096 times.
✓ Branch 2 taken 519842 times.
✗ Branch 3 not taken.
98907938 if (x >= max_x - 8 && cnt == 2) return false;
6921
2/2
✓ Branch 0 taken 372113 times.
✓ Branch 1 taken 98535825 times.
98907938 if (y >= max_y) return false;
6922
6923
3/4
✓ Branch 0 taken 98374065 times.
✓ Branch 1 taken 161760 times.
✓ Branch 2 taken 161760 times.
✗ Branch 3 not taken.
98535825 return effectflag(x, y, layer) || (cnt == 2 && effectflag(x + 8, y, layer));
6924 98909701 }
6925
6926 // used by mapdata->isSolid(x,y) in ZScript
6927 bool _walkflag(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
6928 {
6929 int x = zx.getRound(), y = zy.getRound();
6930 {
6931 int max_x = 256;
6932 int max_y = 176;
6933 if (!get_qr(qr_LTTPWALK))
6934 {
6935 max_x -= 7;
6936 max_y -= 7;
6937 }
6938 if (x < 0 || y < 0) return false;
6939 if (x >= max_x) return false;
6940 if (x >= max_x - 8 && cnt == 2) return false;
6941 if (y >= max_y) return false;
6942 }
6943
6944 const mapscr *s1, *s2;
6945
6946 if ( m->layermap[0] > 0 )
6947 {
6948 s1 = get_canonical_scr(m->layermap[0], m->layerscreen[0]);
6949 }
6950 else s1 = m;
6951
6952 if ( m->layermap[1] > 0 )
6953 {
6954 s2 = get_canonical_scr(m->layermap[1], m->layerscreen[1]);
6955 }
6956 else s2 = m;
6957
6958 zfix unused;
6959 return _walkflag_new(m, s1, s2, x, y, unused, false) || (cnt != 1 && _walkflag_new(m, s1, s2, x + 8, y, unused, false));
6960 }
6961
6962 bool _walkflag_layer(zfix_round x, zfix_round y, int32_t layer, int32_t cnt)
6963 {
6964 DCHECK_LAYER_NEG1_INDEX(layer);
6965 mapscr* m = get_scr_for_world_xy_layer(x, y, layer + 1);
6966 if (!m->is_valid()) return false;
6967 return _walkflag_layer(x, y, cnt, m);
6968 }
6969
6970 static bool _walkflag_layer_new(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m, int max_x, int max_y)
6971 {
6972 int x = zx.getRound(), y = zy.getRound();
6973
6974 if (!get_qr(qr_LTTPWALK))
6975 {
6976 max_x -= 7;
6977 max_y -= 7;
6978 }
6979 if (x < 0 || y < 0) return false;
6980 if (x >= max_x) return false;
6981 if (x >= max_x - 8 && cnt == 2) return false;
6982 if (y >= max_y) return false;
6983
6984 if(!m) return true;
6985
6986 int pos = COMBOPOS(x%256, y%176);
6987 const newcombo* c = &combobuf[m->data[pos]];
6988 bool dried = ((iswater_type(c->type)) && DRIEDLAKE);
6989 int32_t b=1;
6990
6991 if(x&8) b<<=2;
6992
6993 if(y&8) b<<=1;
6994
6995 if((c->walk&b) && !dried)
6996 return true;
6997
6998 if(cnt==1) return false;
6999
7000 ++pos;
7001
7002 if(!(x&8))
7003 b<<=2;
7004 else
7005 {
7006 c = &combobuf[m->data[pos]];
7007 dried = ((iswater_type(c->type)) && DRIEDLAKE);
7008 b=1;
7009
7010 if(y&8) b<<=1;
7011 }
7012
7013 return (c->walk&b) ? !dried : false;
7014 }
7015
7016 //Only check the given mapscr*, not its layer 1&2
7017 bool _walkflag_layer(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
7018 {
7019 return _walkflag_layer_new(zx, zy, cnt, m, world_w, world_h);
7020 }
7021
7022 bool _walkflag_layer_scrolling(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
7023 {
7024 return _walkflag_layer_new(zx, zy, cnt, m, scrolling_region.width, scrolling_region.height);
7025 }
7026
7027 331739 bool _effectflag_layer(int32_t x, int32_t y, int32_t layer, int32_t cnt, bool notLink)
7028 {
7029 DCHECK_LAYER_NEG1_INDEX(layer);
7030 331739 mapscr* m = get_scr_for_world_xy_layer(x, y, layer + 1);
7031
2/2
✓ Branch 0 taken 1762 times.
✓ Branch 1 taken 329977 times.
331739 if (!m->is_valid()) return false;
7032 329977 return _effectflag_layer(x, y, cnt, m, notLink);
7033 331739 }
7034
7035 393086 bool _effectflag_layer(int32_t x,int32_t y,int32_t cnt, mapscr* m, bool notLink)
7036 {
7037 393086 int max_x = world_w;
7038 393086 int max_y = world_h;
7039
3/4
✓ Branch 0 taken 50002 times.
✓ Branch 1 taken 343084 times.
✓ Branch 2 taken 50002 times.
✗ Branch 3 not taken.
393086 if (!get_qr(qr_LTTPWALK) && !notLink)
7040 {
7041 max_x -= 7;
7042 max_y -= 7;
7043 }
7044
2/4
✓ Branch 0 taken 393086 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 393086 times.
393086 if (x < 0 || y < 0) return false;
7045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 393086 times.
393086 if (x >= max_x) return false;
7046
3/4
✓ Branch 0 taken 1209 times.
✓ Branch 1 taken 391877 times.
✓ Branch 2 taken 1209 times.
✗ Branch 3 not taken.
393086 if (x >= max_x - 8 && cnt == 2) return false;
7047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 393086 times.
393086 if (y >= max_y) return false;
7048
7049
1/2
✓ Branch 0 taken 393086 times.
✗ Branch 1 not taken.
393086 if (!m) return true;
7050
7051 393086 int pos = COMBOPOS(x%256, y%176);
7052 393086 const newcombo* c = &combobuf[m->data[pos]];
7053
3/4
✓ Branch 0 taken 392705 times.
✓ Branch 1 taken 381 times.
✓ Branch 2 taken 381 times.
✗ Branch 3 not taken.
393467 bool dried = ((iswater_type(c->type)) && DRIEDLAKE);
7054 393086 int32_t b=1;
7055
7056
2/2
✓ Branch 0 taken 212080 times.
✓ Branch 1 taken 181006 times.
393086 if(x&8) b<<=2;
7057
7058
2/2
✓ Branch 0 taken 158925 times.
✓ Branch 1 taken 234161 times.
393086 if(y&8) b<<=1;
7059
7060
3/4
✓ Branch 0 taken 324092 times.
✓ Branch 1 taken 68994 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 324092 times.
393086 if(((c->walk>>4)&b) && !dried)
7061 324092 return true;
7062
7063
1/2
✓ Branch 0 taken 68994 times.
✗ Branch 1 not taken.
68994 if(cnt==1) return false;
7064
7065 ++pos;
7066
7067 if(!(x&8))
7068 b<<=2;
7069 else
7070 {
7071 c = &combobuf[m->data[pos]];
7072 dried = ((iswater_type(c->type)) && DRIEDLAKE);
7073 b=1;
7074
7075 if(y&8) b<<=1;
7076 }
7077
7078 return ((c->walk>>4)&b) ? !dried : false;
7079 393086 }
7080
7081 811187 bool water_walkflag(int32_t x, int32_t y, int32_t cnt)
7082 {
7083 811187 int max_x = world_w;
7084 811187 int max_y = world_h;
7085
2/2
✓ Branch 0 taken 117367 times.
✓ Branch 1 taken 693820 times.
811187 if (!get_qr(qr_LTTPWALK))
7086 {
7087 693820 max_x -= 7;
7088 693820 max_y -= 7;
7089 693820 }
7090
2/4
✓ Branch 0 taken 811187 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 811187 times.
811187 if (x < 0 || y < 0) return false;
7091
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 811187 times.
811187 if (x >= max_x) return false;
7092
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 811187 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
811187 if (x >= max_x - 8 && cnt == 2) return false;
7093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 811187 times.
811187 if (y >= max_y) return false;
7094
7095
3/4
✓ Branch 0 taken 16825 times.
✓ Branch 1 taken 794362 times.
✓ Branch 2 taken 794362 times.
✗ Branch 3 not taken.
811187 return water_walkflag(x, y) || (cnt != 1 && water_walkflag(x + 8, y));
7096 811187 }
7097
7098 811187 bool water_walkflag(int32_t x, int32_t y)
7099 {
7100 811187 const newcombo& c = combobuf[MAPCOMBO2(-1, x, y)];
7101 811187 const newcombo& c1 = combobuf[MAPCOMBO2(0, x, y)];
7102 811187 const newcombo& c2 = combobuf[MAPCOMBO2(1, x, y)];
7103
7104 811187 int32_t b=1;
7105
2/2
✓ Branch 0 taken 413968 times.
✓ Branch 1 taken 397219 times.
811187 if(x&8) b<<=2;
7106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 811187 times.
811187 if(y&8) b<<=1;
7107
7108
2/2
✓ Branch 0 taken 26377 times.
✓ Branch 1 taken 784810 times.
811187 if(get_qr(qr_NO_SOLID_SWIM))
7109 {
7110
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 26245 times.
26377 if(c.walk&b)
7111 132 return true;
7112
7113
2/2
✓ Branch 0 taken 292 times.
✓ Branch 1 taken 25953 times.
26245 if(c1.walk&b)
7114 292 return true;
7115
7116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25953 times.
25953 if(c2.walk&b)
7117 return true;
7118 25953 }
7119 else
7120 {
7121
4/4
✓ Branch 0 taken 36133 times.
✓ Branch 1 taken 748677 times.
✓ Branch 2 taken 19762 times.
✓ Branch 3 taken 16371 times.
784810 if((c.walk&b) && !iswater_type(c.type))
7122 16371 return true;
7123
7124
3/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 768422 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
768439 if((c1.walk&b) && !iswater_type(c1.type))
7125 17 return true;
7126
7127
3/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 768409 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
768422 if((c2.walk&b) && !iswater_type(c2.type))
7128 13 return true;
7129 }
7130
7131 794362 return false;
7132 811187 }
7133
7134 561145 bool hit_walkflag(int32_t x,int32_t y,int32_t cnt)
7135 {
7136
2/2
✓ Branch 0 taken 89684 times.
✓ Branch 1 taken 471461 times.
561145 if(dlevel)
7137
8/8
✓ Branch 0 taken 470061 times.
✓ Branch 1 taken 1400 times.
✓ Branch 2 taken 466874 times.
✓ Branch 3 taken 3187 times.
✓ Branch 4 taken 465214 times.
✓ Branch 5 taken 1660 times.
✓ Branch 6 taken 4186 times.
✓ Branch 7 taken 461028 times.
471461 if(x<32 || y<40 || (x+(cnt-1)*8)>=world_w-32 || y>=world_h-32)
7138 10433 return true;
7139
7140
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 550710 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
550712 if(blockpath && y<((get_qr(qr_LTTPCOLLISION))?80:88))
7141 return true;
7142
7143
8/8
✓ Branch 0 taken 550445 times.
✓ Branch 1 taken 267 times.
✓ Branch 2 taken 550219 times.
✓ Branch 3 taken 226 times.
✓ Branch 4 taken 550013 times.
✓ Branch 5 taken 206 times.
✓ Branch 6 taken 346 times.
✓ Branch 7 taken 549667 times.
550712 if(x<16 || y<16 || (x+(cnt-1)*8)>=world_w-16 || y>=world_h-16)
7144 1045 return true;
7145
7146 // for(int32_t i=0; i<4; i++)
7147
4/4
✓ Branch 0 taken 841 times.
✓ Branch 1 taken 548826 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 805 times.
549667 if(mblock2.clk && mblock2.hit(x,y,0,cnt*8,1,16))
7148 36 return true;
7149
7150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 549631 times.
549631 if (collide_object(x, y,cnt*8, 1))
7151 return true;
7152
7153 549631 return _walkflag(x,y,cnt);
7154 561145 }
7155
7156 12110 bool solpush_walkflag(int32_t x, int32_t y, int32_t cnt, solid_object const* ign)
7157 {
7158 // 16 pixel buffer to account for slopes that are on bordering screens.
7159
4/8
✓ Branch 0 taken 12110 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12110 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12110 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 12110 times.
12110 if(x<0 || y<0 || x>=world_w+16 || y>=world_h+16)
7160 return true;
7161
7162 // for(int32_t i=0; i<4; i++)
7163
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12110 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12110 if(mblock2.clk && mblock2.hit(x,y,0,cnt*8,1,16))
7164 return true;
7165
7166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12110 times.
12110 if (collide_object(x, y,cnt*8, 1, ign))
7167 return true;
7168
7169 12110 return _walkflag(x,y,cnt);
7170 12110 }
7171
7172 37734 void map_bkgsfx(bool on)
7173 {
7174
2/2
✓ Branch 0 taken 37713 times.
✓ Branch 1 taken 21 times.
37734 if(on)
7175 {
7176 37713 cont_sfx(hero_scr->oceansfx);
7177
7178
4/4
✓ Branch 0 taken 367 times.
✓ Branch 1 taken 37346 times.
✓ Branch 2 taken 314 times.
✓ Branch 3 taken 53 times.
37713 if(hero_scr->bosssfx && !(game->lvlitems[dlevel]&liBOSS))
7179 314 cont_sfx(hero_scr->bosssfx);
7180 37713 }
7181 else
7182 {
7183 21 adjust_sfx(hero_scr->oceansfx,128,false);
7184 21 adjust_sfx(hero_scr->bosssfx,128,false);
7185
7186
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 21 times.
135 for(int32_t i=0; i<guys.Count(); i++)
7187 {
7188
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 84 times.
114 if(((enemy*)guys.spr(i))->bgsfx)
7189 84 stop_sfx(((enemy*)guys.spr(i))->bgsfx);
7190 114 }
7191 }
7192 37734 }
7193
7194 239 void toggle_switches(dword flags, bool entry)
7195 {
7196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 239 times.
239 if(!flags) return; //No flags to toggle
7197
7198 478 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7199 239 toggle_switches(flags, entry, create_screen_handles(scr));
7200 239 });
7201 239 }
7202 53942 void toggle_switches(dword flags, bool entry, const screen_handles_t& screen_handles)
7203 {
7204
2/2
✓ Branch 0 taken 737 times.
✓ Branch 1 taken 53205 times.
53942 if(!flags) return; //No flags to toggle
7205
7206 737 mapscr* m = screen_handles[0].base_scr;
7207 737 int screen = m->screen;
7208 737 bool is_active_screen = is_in_current_region(m);
7209
7210 305041 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
7211 304304 byte togglegrid[176] = {0};
7212 304304 mapscr* scr = rpos_handle.scr;
7213 304304 int lyr = rpos_handle.layer;
7214 304304 int pos = rpos_handle.pos;
7215 304304 newcombo const& cmb = combobuf[scr->data[pos]];
7216
2/2
✓ Branch 0 taken 39424 times.
✓ Branch 1 taken 264880 times.
304304 if(is_active_screen)
7217
2/2
✓ Branch 0 taken 264880 times.
✓ Branch 1 taken 102893 times.
367773 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7218 {
7219 102893 auto& trig = cmb.triggers[idx];
7220
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 102893 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
102893 if((trig.triggerflags[3] & combotriggerTRIGLEVELSTATE) && trig.trig_lstate < 32)
7221 if(flags&(1<<trig.trig_lstate))
7222 {
7223 auto oldcombo = rpos_handle.data();
7224 do_trigger_combo(rpos_handle, idx, ctrigSWITCHSTATE);
7225 if(rpos_handle.data() != oldcombo) break;
7226 }
7227 367773 }
7228
3/4
✓ Branch 0 taken 303641 times.
✓ Branch 1 taken 663 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2760 times.
304304 if((cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && cmb.attribytes[0] < 32
7229
2/2
✓ Branch 0 taken 2760 times.
✓ Branch 1 taken 301544 times.
304304 && !(cmb.usrflags & cflag11)) //global state
7230 {
7231
2/2
✓ Branch 0 taken 446 times.
✓ Branch 1 taken 2314 times.
2760 if(flags&(1<<cmb.attribytes[0]))
7232 {
7233 2314 set<int32_t> oldData;
7234 //Increment the combo/cset by the attributes
7235 2314 int32_t cmbofs = (cmb.attributes[0]/10000L);
7236 2314 int32_t csofs = (cmb.attributes[1]/10000L);
7237
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 oldData.insert(scr->data[pos]);
7238
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 scr->data[pos] = BOUND_COMBO(scr->data[pos] + cmbofs);
7239 2314 scr->cset[pos] = (scr->cset[pos] + csofs) & 15;
7240
4/4
✓ Branch 0 taken 1435 times.
✓ Branch 1 taken 879 times.
✓ Branch 2 taken 1197 times.
✓ Branch 3 taken 238 times.
2314 if(entry && (cmb.usrflags&cflag8))
7241 {
7242 238 newcombo const* tmp = &combobuf[scr->data[pos]];
7243
2/4
✓ Branch 0 taken 238 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 238 times.
✗ Branch 3 not taken.
238 while(tmp->can_cycle())
7244 {
7245 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7246 auto cid = cycle_under ? scr->undercombo : tmp->nextcombo;
7247 if(oldData.find(cid) != oldData.end())
7248 break;
7249
7250 scr->data[pos] = cid;
7251 if(!(tmp->animflags & AF_CYCLENOCSET))
7252 scr->cset[pos] = cycle_under ? scr->undercset : tmp->nextcset;
7253 oldData.insert(cid);
7254 tmp = &combobuf[cid];
7255 }
7256 238 }
7257 2314 int32_t cmbid = scr->data[pos];
7258
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 2273 times.
2314 if(combobuf[cmbid].animflags & AF_CYCLE)
7259 {
7260 41 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7261 41 combobuf[cmbid].cur_frame=0;
7262 41 combobuf[cmbid].aclk = 0;
7263
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 combo_caches::drawing.refresh(cmbid);
7264 41 }
7265 2314 togglegrid[pos] |= (1<<lyr); //Mark this pos toggled for this layer
7266
2/2
✓ Branch 0 taken 511 times.
✓ Branch 1 taken 1803 times.
2314 if(cmb.type == cCSWITCH) return; //Switches don't toggle other layers
7267
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2147 times.
2147 for(int32_t lyr2 = 0; lyr2 < 7; ++lyr2) //Toggle same pos on other layers, if flag set
7268 {
7269
2/2
✓ Branch 0 taken 1671 times.
✓ Branch 1 taken 476 times.
2147 if(lyr==lyr2) return;
7270
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 344 times.
476 if(!(cmb.usrflags&(1<<lyr2))) return;
7271
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 if(togglegrid[pos]&(1<<lyr2)) return;
7272
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
344 mapscr* scr_2 = (lyr2 ? get_scr_layer(screen, lyr2) : m);
7273
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 if(!scr_2->data[pos]) //Don't increment empty space
7274 return;
7275 344 newcombo const& cmb_2 = combobuf[scr_2->data[pos]];
7276
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
344 if(lyr2 > lyr && (cmb_2.type == cCSWITCH || cmb_2.type == cCSWITCHBLOCK) && !(cmb.usrflags & cflag11)
7277 && cmb_2.attribytes[0] < 32 && (flags&(1<<cmb_2.attribytes[0])))
7278 return; //This is a switch/block that will be hit later in the loop!
7279 344 set<int32_t> oldData2;
7280 //Increment the combo/cset by the original cmb's attributes
7281
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 oldData2.insert(scr_2->data[pos]);
7282
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 scr_2->data[pos] = BOUND_COMBO(scr_2->data[pos] + cmbofs);
7283 344 scr_2->cset[pos] = (scr_2->cset[pos] + csofs) & 15;
7284
3/4
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 294 times.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
344 if(entry && (cmb.usrflags&cflag8)) //Skip cycling on screen entry
7285 {
7286 newcombo const* tmp = &combobuf[scr_2->data[pos]];
7287 while(tmp->can_cycle())
7288 {
7289 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7290 auto cid = cycle_under ? scr_2->undercombo : tmp->nextcombo;
7291 if(oldData2.find(cid) != oldData2.end())
7292 break;
7293
7294 scr_2->data[pos] = cid;
7295 if(!(tmp->animflags & AF_CYCLENOCSET))
7296 scr_2->cset[pos] = cycle_under ? scr_2->undercset : tmp->nextcset;
7297 oldData2.insert(cid);
7298 tmp = &combobuf[cid];
7299 }
7300 }
7301 344 int32_t cmbid2 = scr_2->data[pos];
7302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
344 if(combobuf[cmbid2].animflags & AF_CYCLE)
7303 {
7304 combobuf[cmbid2].tile = combobuf[cmbid2].o_tile;
7305 combobuf[cmbid2].cur_frame=0;
7306 combobuf[cmbid2].aclk = 0;
7307 combo_caches::drawing.refresh(cmbid2);
7308 }
7309 344 togglegrid[pos] |= (1<<lyr2); //Mark this pos toggled for this layer
7310 344 }
7311
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 2314 times.
✗ Branch 2 not taken.
2314 }
7312 446 }
7313 304304 });
7314
7315
3/4
✓ Branch 0 taken 519 times.
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 519 times.
✗ Branch 3 not taken.
737 if(get_qr(qr_SWITCHES_AFFECT_MOVINGBLOCKS) && mblock2.clk)
7316 {
7317 newcombo const& cmb = combobuf[mblock2.bcombo];
7318 if(!(cmb.usrflags & cflag11) && (cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && cmb.attribytes[0] < 32)
7319 {
7320 if(flags&(1<<cmb.attribytes[0]))
7321 {
7322 //Increment the combo/cset by the attributes
7323 int32_t cmbofs = (cmb.attributes[0]/10000L);
7324 int32_t csofs = (cmb.attributes[1]/10000L);
7325 mblock2.bcombo = BOUND_COMBO(mblock2.bcombo + cmbofs);
7326 mblock2.cs = (mblock2.cs + csofs) & 15;
7327 int32_t cmbid = mblock2.bcombo;
7328 if(combobuf[cmbid].animflags & AF_CYCLE)
7329 {
7330 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7331 combobuf[cmbid].cur_frame=0;
7332 combobuf[cmbid].aclk = 0;
7333 combo_caches::drawing.refresh(cmbid);
7334 }
7335 }
7336 }
7337 }
7338
7339
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 513 times.
737 if (is_active_screen)
7340 {
7341 513 int screen_index_offset = get_region_screen_offset(m->screen);
7342 513 word c = m->numFFC();
7343
2/2
✓ Branch 0 taken 334 times.
✓ Branch 1 taken 513 times.
847 for (int q = 0; q < c; ++q)
7344 {
7345 334 auto ffc_handle = *m->getFFCHandle(q, screen_index_offset);
7346 334 auto& cmb = ffc_handle.combo();
7347
2/2
✓ Branch 0 taken 334 times.
✓ Branch 1 taken 29 times.
363 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7348 {
7349 29 auto& trig = cmb.triggers[idx];
7350
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
29 if((trig.triggerflags[3] & combotriggerTRIGLEVELSTATE) && trig.trig_lstate < 32)
7351 if(flags&(1<<trig.trig_lstate))
7352 {
7353 auto oldcombo = ffc_handle.data();
7354 do_trigger_combo(ffc_handle, idx, ctrigSWITCHSTATE);
7355 if(ffc_handle.data() != oldcombo) break;
7356 }
7357 29 }
7358 334 }
7359 513 }
7360 53942 }
7361
7362 void toggle_gswitches(int32_t state, bool entry)
7363 {
7364 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7365 toggle_gswitches(state, entry, create_screen_handles(scr));
7366 });
7367 }
7368 void toggle_gswitches(int32_t state, bool entry, const screen_handles_t& screen_handles)
7369 {
7370 bool states[256] = {false};
7371 states[state] = true;
7372 toggle_gswitches(states, entry, screen_handles);
7373 }
7374 15161202 void toggle_gswitches(bool* states, bool entry, const screen_handles_t& screen_handles)
7375 {
7376
1/2
✓ Branch 0 taken 15161202 times.
✗ Branch 1 not taken.
15161202 if(!states) return;
7377
7378 15161202 auto& combo_cache = combo_caches::gswitch;
7379 15161202 mapscr* base_scr = screen_handles[0].base_scr;
7380 15161202 int screen = base_scr->screen;
7381 15161202 bool is_active_screen = is_in_current_region(base_scr);
7382 15161202 byte togglegrid[176] = {0};
7383
2/2
✓ Branch 0 taken 15161202 times.
✓ Branch 1 taken 106128414 times.
121289616 for(int32_t lyr = 0; lyr <= 6; ++lyr)
7384 {
7385 106128414 mapscr* scr = screen_handles[lyr].scr;
7386
2/2
✓ Branch 0 taken 73929331 times.
✓ Branch 1 taken 32199083 times.
106128414 if (!scr)
7387 73929331 continue;
7388
7389
2/2
✓ Branch 0 taken 5667038608 times.
✓ Branch 1 taken 32199083 times.
5699237691 for(int32_t pos = 0; pos < 176; ++pos)
7390 {
7391 5667038608 int cid = scr->data[pos];
7392 5667038608 auto& mini_cmb = combo_cache.minis[cid];
7393
7394
2/2
✓ Branch 0 taken 92991360 times.
✓ Branch 1 taken 5574047248 times.
5667038608 if (is_active_screen)
7395 {
7396
2/2
✓ Branch 0 taken 5574045366 times.
✓ Branch 1 taken 1882 times.
5574047248 if (mini_cmb.trigger_global_state)
7397 {
7398 1882 auto& cmb = combobuf[cid];
7399
2/2
✓ Branch 0 taken 1882 times.
✓ Branch 1 taken 1882 times.
3764 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7400 {
7401 1882 auto& trig = cmb.triggers[idx];
7402
2/4
✓ Branch 0 taken 1882 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1882 times.
✗ Branch 3 not taken.
1882 if ((trig.triggerflags[3] & combotriggerTRIGGLOBALSTATE) && states[trig.trig_gstate])
7403 {
7404 auto rpos_handle = get_rpos_handle_for_screen(screen, lyr, pos);
7405 do_trigger_combo(rpos_handle, idx, ctrigSWITCHSTATE);
7406 if(rpos_handle.data() != cid) break;
7407 }
7408 1882 }
7409 1882 }
7410 5574047248 }
7411
7412
2/2
✓ Branch 0 taken 40395 times.
✓ Branch 1 taken 5666998213 times.
5667038608 if (!mini_cmb.has_global_state)
7413 5666998213 continue;
7414
7415 40395 newcombo const& cmb = combobuf[cid];
7416
2/4
✓ Branch 0 taken 40395 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40395 times.
40395 if(cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK)
7417 {
7418 if(states[cmb.attribytes[0]])
7419 {
7420 set<int32_t> oldData;
7421 //Increment the combo/cset by the attributes
7422 int32_t cmbofs = (cmb.attributes[0]/10000L);
7423 int32_t csofs = (cmb.attributes[1]/10000L);
7424 oldData.insert(scr->data[pos]);
7425 scr->data[pos] = BOUND_COMBO(scr->data[pos] + cmbofs);
7426 scr->cset[pos] = (scr->cset[pos] + csofs) & 15;
7427 if(entry && (cmb.usrflags&cflag8))
7428 {
7429 newcombo const* tmp = &combobuf[scr->data[pos]];
7430 while(tmp->can_cycle())
7431 {
7432 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7433 auto cid = cycle_under ? scr->undercombo : tmp->nextcombo;
7434 if(oldData.find(cid) != oldData.end())
7435 break;
7436 scr->data[pos] = cid;
7437 if(!(tmp->animflags & AF_CYCLENOCSET))
7438 scr->cset[pos] = cycle_under ? scr->undercset : tmp->nextcset;
7439 oldData.insert(cid);
7440 tmp = &combobuf[cid];
7441 }
7442 }
7443 int32_t cmbid = scr->data[pos];
7444 if(combobuf[cmbid].animflags & AF_CYCLE)
7445 {
7446 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7447 combobuf[cmbid].cur_frame=0;
7448 combobuf[cmbid].aclk = 0;
7449 combo_caches::drawing.refresh(cmbid);
7450 }
7451 togglegrid[pos] |= (1<<lyr); //Mark this pos toggled for this layer
7452 if(cmb.type == cCSWITCH) continue; //Switches don't toggle other layers
7453 for(int32_t lyr2 = 0; lyr2 <= 6; ++lyr2) //Toggle same pos on other layers, if flag set
7454 {
7455 if(lyr==lyr2) continue;
7456 if(!(cmb.usrflags&(1<<lyr2))) continue;
7457 if(togglegrid[pos]&(1<<lyr2)) continue;
7458 mapscr* scr_2 = lyr2 == 0 ? base_scr : get_scr_layer_valid(screen, lyr2);
7459 if(!scr_2 || !scr_2->data[pos]) //Don't increment empty space
7460 continue;
7461 newcombo const& cmb_2 = combobuf[scr_2->data[pos]];
7462 if(lyr2 > lyr && (cmb_2.type == cCSWITCH || cmb_2.type == cCSWITCHBLOCK)
7463 && (cmb_2.usrflags & cflag11) && (states[cmb_2.attribytes[0]]))
7464 continue; //This is a switch/block that will be hit later in the loop!
7465 set<int32_t> oldData2;
7466 //Increment the combo/cset by the original cmb's attributes
7467 oldData2.insert(scr_2->data[pos]);
7468 scr_2->data[pos] = BOUND_COMBO(scr_2->data[pos] + cmbofs);
7469 scr_2->cset[pos] = (scr_2->cset[pos] + csofs) & 15;
7470 if(entry && (cmb.usrflags&cflag8)) //Skip cycling on screen entry
7471 {
7472 newcombo const* tmp = &combobuf[scr_2->data[pos]];
7473 while(tmp->can_cycle())
7474 {
7475 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7476 auto cid = cycle_under ? scr_2->undercombo : tmp->nextcombo;
7477 if(oldData2.find(cid) != oldData2.end())
7478 break;
7479 scr_2->data[pos] = cid;
7480 if(!(tmp->animflags & AF_CYCLENOCSET))
7481 scr_2->cset[pos] = cycle_under ? scr_2->undercset : tmp->nextcset;
7482 oldData2.insert(cid);
7483 tmp = &combobuf[cid];
7484 }
7485 }
7486 int32_t cmbid2 = scr_2->data[pos];
7487 if(combobuf[cmbid2].animflags & AF_CYCLE)
7488 {
7489 combobuf[cmbid2].tile = combobuf[cmbid2].o_tile;
7490 combobuf[cmbid2].cur_frame=0;
7491 combobuf[cmbid2].aclk = 0;
7492 combo_caches::drawing.refresh(cmbid2);
7493 }
7494 togglegrid[pos] |= (1<<lyr2); //Mark this pos toggled for this layer
7495 }
7496 }
7497 }
7498 40395 }
7499 32199083 }
7500
7501
4/4
✓ Branch 0 taken 552270 times.
✓ Branch 1 taken 14608932 times.
✓ Branch 2 taken 4744 times.
✓ Branch 3 taken 547526 times.
15161202 if(get_qr(qr_SWITCHES_AFFECT_MOVINGBLOCKS) && mblock2.clk)
7502 {
7503 4744 newcombo const& cmb = combobuf[mblock2.bcombo];
7504
2/4
✓ Branch 0 taken 4744 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4744 times.
✗ Branch 3 not taken.
4744 if((cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && (cmb.usrflags & cflag11))
7505 {
7506 if(states[cmb.attribytes[0]])
7507 {
7508 //Increment the combo/cset by the attributes
7509 int32_t cmbofs = (cmb.attributes[0]/10000L);
7510 int32_t csofs = (cmb.attributes[1]/10000L);
7511 mblock2.bcombo = BOUND_COMBO(mblock2.bcombo + cmbofs);
7512 mblock2.cs = (mblock2.cs + csofs) & 15;
7513 int32_t cmbid = mblock2.bcombo;
7514 if(combobuf[cmbid].animflags & AF_CYCLE)
7515 {
7516 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7517 combobuf[cmbid].cur_frame=0;
7518 combobuf[cmbid].aclk = 0;
7519 combo_caches::drawing.refresh(cmbid);
7520 }
7521 }
7522 }
7523 4744 }
7524
7525
2/2
✓ Branch 0 taken 410733 times.
✓ Branch 1 taken 14750469 times.
15161202 if(is_active_screen)
7526 {
7527 14750469 int screen_index_offset = get_region_screen_offset(screen);
7528 14750469 word c = base_scr->numFFC();
7529
2/2
✓ Branch 0 taken 439949586 times.
✓ Branch 1 taken 14750469 times.
454700055 for (int q = 0; q < c; ++q)
7530 {
7531 439949586 auto ffc_handle = *base_scr->getFFCHandle(q, screen_index_offset);
7532 439949586 int cid = ffc_handle.data();
7533 // auto& mini_cmb = combo_cache.minis[cid];
7534 // if (mini_cmb.trigger_global_state)
7535 439949586 auto& cmb = combobuf[cid];
7536
2/2
✓ Branch 0 taken 439949586 times.
✓ Branch 1 taken 228788 times.
440178374 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7537 {
7538 228788 auto& trig = cmb.triggers[idx];
7539
1/2
✓ Branch 0 taken 228788 times.
✗ Branch 1 not taken.
228788 if (states[trig.trig_gstate])
7540 do_trigger_combo(ffc_handle, idx, ctrigSWITCHSTATE);
7541
1/2
✓ Branch 0 taken 228788 times.
✗ Branch 1 not taken.
228788 if(ffc_handle.data() != cid) break;
7542 228788 }
7543 439949586 }
7544 14750469 }
7545 15161202 }
7546 53703 void toggle_gswitches_load(const screen_handles_t& screen_handles)
7547 {
7548 bool states[256];
7549
2/2
✓ Branch 0 taken 13747968 times.
✓ Branch 1 taken 53703 times.
13801671 for(auto q = 0; q < 256; ++q)
7550 {
7551 13747968 states[q] = game->gswitch_timers[q] != 0;
7552 13747968 }
7553 53703 toggle_gswitches(states, true, screen_handles);
7554 53703 }
7555 14718131 void run_gswitch_timers()
7556 {
7557 14718131 bool states[256] = {false};
7558 14718131 auto& m = game->gswitch_timers.mut_inner();
7559
2/2
✓ Branch 0 taken 3763799296 times.
✓ Branch 1 taken 14718131 times.
3778517427 for(auto it = m.begin(); it != m.end();)
7560 {
7561
1/2
✓ Branch 0 taken 3763799296 times.
✗ Branch 1 not taken.
3763799296 if(it->second > 0)
7562 if(!--it->second)
7563 {
7564 states[it->first] = true;
7565 it = m.erase(it);
7566 continue;
7567 }
7568 3763799296 ++it;
7569 }
7570 29825630 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7571 15107499 toggle_gswitches(states, false, create_screen_handles(scr));
7572 15107499 });
7573 14718131 }
7574 1113 void onload_gswitch_timers() //Reset all timers that were counting down, no trigger necessary
7575 {
7576
2/2
✓ Branch 0 taken 284928 times.
✓ Branch 1 taken 1113 times.
286041 for(auto q = 0; q < 256; ++q)
7577 {
7578
1/2
✓ Branch 0 taken 284928 times.
✗ Branch 1 not taken.
284928 if(game->gswitch_timers[q] > 0)
7579 game->gswitch_timers[q] = 0;
7580 284928 }
7581 1113 }
7582
7583 /**** View Map ****/
7584
7585 int32_t mapres = 0;
7586 int32_t view_map_show_mode = 3;
7587
7588 124544 bool displayOnMap(int32_t x, int32_t y)
7589 {
7590 124544 int32_t s = (y<<4) + x;
7591 124544 int mi = mapind(cur_map, s);
7592
2/2
✓ Branch 0 taken 67891 times.
✓ Branch 1 taken 56653 times.
124544 if (!(game->maps[mi]&mVISITED))
7593 67891 return false;
7594
7595 // Don't display if not part of DMap
7596
4/4
✓ Branch 0 taken 15628 times.
✓ Branch 1 taken 41025 times.
✓ Branch 2 taken 4655 times.
✓ Branch 3 taken 4311 times.
65619 if(((DMaps[cur_dmap].flags&dmfDMAPMAP) &&
7597
1/2
✓ Branch 0 taken 15628 times.
✗ Branch 1 not taken.
15628 (DMaps[cur_dmap].type != dmOVERW) &&
7598
2/2
✓ Branch 0 taken 12495 times.
✓ Branch 1 taken 3133 times.
15628 !(x >= DMaps[cur_dmap].xoff &&
7599
2/2
✓ Branch 0 taken 8966 times.
✓ Branch 1 taken 3529 times.
12495 x < DMaps[cur_dmap].xoff+8 &&
7600 8966 DMaps[cur_dmap].grid[y]&(128>>(x-DMaps[cur_dmap].xoff)))))
7601 10973 return false;
7602 else
7603 45680 return true;
7604 124544 }
7605
7606 973 void ViewMap()
7607 {
7608 973 ViewingMap = true;
7609
7610 973 BITMAP* mappic = NULL;
7611 static double scales[17] =
7612 {
7613 0.03125, 0.04419, 0.0625, 0.08839, 0.125, 0.177, 0.25, 0.3535,
7614 0.50, 0.707, 1.0, 1.414, 2.0, 2.828, 4.0, 5.657, 8.0
7615 };
7616
7617 973 int32_t px = ((8-(cur_screen&15)) << 9) - 256;
7618 973 int32_t py = ((4-(cur_screen>>4)) * 352) - 176;
7619 973 int32_t lx = ((cur_screen&15)<<8) + HeroX()+8;
7620 973 int32_t ly = ((cur_screen>>4)*176) + HeroY()+8;
7621 973 int32_t sc = 6;
7622
7623 973 bool done=false, redraw=true;
7624
7625 973 mappic = create_bitmap_ex(8,(256*16)>>mapres,(176*8)>>mapres);
7626
7627
1/2
✓ Branch 0 taken 973 times.
✗ Branch 1 not taken.
973 if(!mappic)
7628 {
7629 enter_sys_pal();
7630 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
7631 exit_sys_pal();
7632 return;
7633 }
7634
7635 973 clear_to_color(mappic, WHITE);
7636
7637 973 auto prev_viewport = viewport;
7638 973 viewport.x = 0;
7639 973 viewport.y = 0;
7640
7641 // draw the map
7642 973 BITMAP* screen_bmp = create_bitmap_ex(8, 256, 176);
7643 973 combotile_add_x = 256;
7644 973 combotile_add_y = 0;
7645
2/2
✓ Branch 0 taken 7784 times.
✓ Branch 1 taken 973 times.
8757 for(int32_t y=0; y<8; y++)
7646 {
7647
2/2
✓ Branch 0 taken 124544 times.
✓ Branch 1 taken 7784 times.
132328 for(int32_t x=0; x<16; x++)
7648 {
7649
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 78864 times.
124544 if (!displayOnMap(x, y))
7650 78864 continue;
7651
7652 45680 int screen = map_scr_xy_to_index(x, y);
7653 45680 auto scrs = loadscr2(screen);
7654 45680 mapscr* scr = &scrs[0];
7655
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if (!scr->is_valid())
7656 continue;
7657
7658 screen_handles_t screen_handles;
7659
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 319760 times.
365440 for (int i = 0; i <= 6; i++)
7660
3/4
✓ Branch 0 taken 319760 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103790 times.
✓ Branch 3 taken 215970 times.
319760 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
7661
7662 45680 int xx = 0;
7663 45680 int yy = -playing_field_offset;
7664
7665
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 45660 times.
45680 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
7666 {
7667
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 do_layer(screen_bmp, 0, screen_handles[2], xx, yy);
7668
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 do_ffc_layer(screen_bmp, -2, screen_handles[0], xx, yy);
7669 20 }
7670
7671
2/2
✓ Branch 0 taken 175 times.
✓ Branch 1 taken 45505 times.
45680 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
7672 {
7673
1/2
✓ Branch 0 taken 175 times.
✗ Branch 1 not taken.
175 do_layer(screen_bmp, 0, screen_handles[3], xx, yy);
7674
1/2
✓ Branch 0 taken 175 times.
✗ Branch 1 not taken.
175 do_ffc_layer(screen_bmp, -3, screen_handles[0], xx, yy);
7675 175 }
7676
7677
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if(lenscheck(scr,0)) putscr(scr, screen_bmp, 0, 0);
7678
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 0, screen_handles[0], xx, yy);
7679
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[1], xx, yy);
7680
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 1, screen_handles[0], xx, yy);
7681
7682
2/2
✓ Branch 0 taken 45660 times.
✓ Branch 1 taken 20 times.
45680 if(!XOR((scr->flags7&fLAYER2BG), DMaps[cur_dmap].flags&dmfLAYER2BG))
7683 {
7684
1/2
✓ Branch 0 taken 45660 times.
✗ Branch 1 not taken.
45660 do_layer(screen_bmp, 0, screen_handles[2], xx, yy);
7685
1/2
✓ Branch 0 taken 45660 times.
✗ Branch 1 not taken.
45660 do_ffc_layer(screen_bmp, 2, screen_handles[0], xx, yy);
7686 45660 }
7687
7688
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 putscrdoors(scr, screen_bmp, xx, yy);
7689
2/2
✓ Branch 0 taken 41678 times.
✓ Branch 1 taken 4002 times.
45680 if (get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
7690 {
7691
1/2
✓ Branch 0 taken 41678 times.
✗ Branch 1 not taken.
41678 do_layer(screen_bmp, -2, screen_handles[0], xx, yy);
7692
2/2
✓ Branch 0 taken 1782 times.
✓ Branch 1 taken 39896 times.
41678 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
7693 {
7694
1/2
✓ Branch 0 taken 1782 times.
✗ Branch 1 not taken.
1782 do_layer(screen_bmp,-2, screen_handles[1], xx, yy);
7695
1/2
✓ Branch 0 taken 1782 times.
✗ Branch 1 not taken.
1782 do_layer(screen_bmp,-2, screen_handles[2], xx, yy);
7696 1782 }
7697 41678 }
7698
7699
2/2
✓ Branch 0 taken 45505 times.
✓ Branch 1 taken 175 times.
45680 if(!XOR((scr->flags7&fLAYER3BG), DMaps[cur_dmap].flags&dmfLAYER3BG))
7700 {
7701
1/2
✓ Branch 0 taken 45505 times.
✗ Branch 1 not taken.
45505 do_layer(screen_bmp, 0, screen_handles[3], xx, yy);
7702
1/2
✓ Branch 0 taken 45505 times.
✗ Branch 1 not taken.
45505 do_ffc_layer(screen_bmp, 3, screen_handles[0], xx, yy);
7703 45505 }
7704
7705
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[4], xx, yy);
7706
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 4, screen_handles[0], xx, yy);
7707
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, -1, screen_handles[0], xx, yy);
7708
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 39896 times.
45680 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
7709 {
7710
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 do_layer(screen_bmp,-1, screen_handles[1], xx, yy);
7711
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 do_layer(screen_bmp,-1, screen_handles[2], xx, yy);
7712 5784 }
7713
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[5], xx, yy);
7714
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 5, screen_handles[0], xx, yy);
7715
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45680 times.
45680 if(replay_version_check(40))
7716 do_ffc_layer(screen_bmp, -1, screen_handles[0], xx, yy);
7717
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[6], xx, yy);
7718
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 6, screen_handles[0], xx, yy);
7719
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 7, screen_handles[0], xx, yy);
7720
7721
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 stretch_blit(screen_bmp, mappic, 0, 0, 256, 176, x<<(8-mapres), (y*176)>>mapres, 256>>mapres, 176>>mapres);
7722
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
45680 }
7723 7784 }
7724
7725 973 viewport = prev_viewport;
7726 973 combotile_add_x = 0;
7727 973 combotile_add_y = 0;
7728
7729 973 destroy_bitmap(screen_bmp);
7730 973 clear_keybuf();
7731 973 pause_all_sfx();
7732
7733 // view it
7734 973 int32_t delay = 0;
7735
7736 973 do
7737 {
7738
2/2
✓ Branch 0 taken 178717 times.
✓ Branch 1 taken 29891 times.
208608 if (replay_version_check(0, 11))
7739 29891 load_control_state();
7740
7741 208608 int32_t step = int32_t(16.0/scales[sc]);
7742 208608 step = (step>>1) + (step&1);
7743 208608 bool r = cRbtn();
7744
7745
1/2
✓ Branch 0 taken 208608 times.
✗ Branch 1 not taken.
208608 if(cLbtn())
7746 {
7747 step <<= 2;
7748 delay = 0;
7749 }
7750
7751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208608 times.
208608 if(r)
7752 {
7753 if(rUp())
7754 {
7755 py+=step;
7756 redraw=true;
7757 }
7758
7759 if(rDown())
7760 {
7761 py-=step;
7762 redraw=true;
7763 }
7764
7765 if(rLeft())
7766 {
7767 px+=step;
7768 redraw=true;
7769 }
7770
7771 if(rRight())
7772 {
7773 px-=step;
7774 redraw=true;
7775 }
7776 }
7777 else
7778 {
7779
2/2
✓ Branch 0 taken 193729 times.
✓ Branch 1 taken 14879 times.
208608 if(Up())
7780 {
7781 14879 py+=step;
7782 14879 redraw=true;
7783 14879 }
7784
7785
2/2
✓ Branch 0 taken 193574 times.
✓ Branch 1 taken 15034 times.
208608 if(Down())
7786 {
7787 15034 py-=step;
7788 15034 redraw=true;
7789 15034 }
7790
7791
2/2
✓ Branch 0 taken 182159 times.
✓ Branch 1 taken 26449 times.
208608 if(Left())
7792 {
7793 26449 px+=step;
7794 26449 redraw=true;
7795 26449 }
7796
7797
2/2
✓ Branch 0 taken 182774 times.
✓ Branch 1 taken 25834 times.
208608 if(Right())
7798 {
7799 25834 px-=step;
7800 25834 redraw=true;
7801 25834 }
7802 }
7803
7804
2/2
✓ Branch 0 taken 187444 times.
✓ Branch 1 taken 21164 times.
208608 if(delay)
7805 21164 --delay;
7806 else
7807 {
7808 187444 bool a = cAbtn();
7809 187444 bool b = cBbtn();
7810
7811
3/4
✓ Branch 0 taken 1721 times.
✓ Branch 1 taken 185723 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1721 times.
187444 if(a && !b)
7812 {
7813
1/2
✓ Branch 0 taken 1721 times.
✗ Branch 1 not taken.
1721 sc=zc_min(sc+1,16);
7814 1721 delay=8;
7815 1721 redraw=true;
7816 1721 }
7817
7818
3/4
✓ Branch 0 taken 927 times.
✓ Branch 1 taken 186517 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 927 times.
187444 if(b && !a)
7819 {
7820
2/2
✓ Branch 0 taken 926 times.
✓ Branch 1 taken 1 times.
927 sc=zc_max(sc-1,0);
7821 927 delay=8;
7822 927 redraw=true;
7823 927 }
7824 }
7825
7826
2/2
✓ Branch 0 taken 208597 times.
✓ Branch 1 taken 11 times.
208608 if(rPbtn())
7827 11 --view_map_show_mode;
7828
7829 208608 px = vbound(px,-4096,4096);
7830 208608 py = vbound(py,-1408,1408);
7831
7832 208608 double scale = scales[sc];
7833
7834
2/2
✓ Branch 0 taken 72838 times.
✓ Branch 1 taken 135770 times.
208608 if(!redraw)
7835 {
7836 135770 blit(scrollbuf_old,framebuf,256,0,0,0,256,232);
7837 135770 }
7838 else
7839 {
7840 72838 clear_to_color(framebuf,BLACK);
7841 145676 stretch_blit(mappic,framebuf,0,0,mappic->w,mappic->h,
7842 72838 int32_t(256+(int64_t(px)-mappic->w)*scale)/2,int32_t(224+(int64_t(py)-mappic->h)*scale)/2,
7843 72838 int32_t(mappic->w*scale),int32_t(mappic->h*scale));
7844
7845 72838 blit(framebuf,scrollbuf_old,0,0,256,0,256,232);
7846 72838 redraw=false;
7847 }
7848
7849 208608 int32_t x = int32_t(256+(px-((2048-int64_t(lx))*2))*scale)/2;
7850 208608 int32_t y = int32_t(224+(py-((704-int64_t(ly))*2))*scale)/2;
7851
7852
2/2
✓ Branch 0 taken 7466 times.
✓ Branch 1 taken 201142 times.
208608 if(view_map_show_mode&1)
7853 {
7854 201142 line(framebuf,x-7,y-7,x+7,y+7,(frame&3)+252);
7855 201142 line(framebuf,x+7,y-7,x-7,y+7,(frame&3)+252);
7856 201142 }
7857
7858
3/4
✓ Branch 0 taken 5600 times.
✓ Branch 1 taken 203008 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5600 times.
208608 if(view_map_show_mode&2 || r)
7859 203008 textprintf_ex(framebuf,font,224,216,WHITE,BLACK,"%1.2f",scale);
7860
7861
1/2
✓ Branch 0 taken 208608 times.
✗ Branch 1 not taken.
208608 if(r)
7862 {
7863 textprintf_ex(framebuf,font,0,208,WHITE,BLACK,"m: %d %d",px,py);
7864 textprintf_ex(framebuf,font,0,216,WHITE,BLACK,"x: %d %d",x,y);
7865 }
7866
7867 208608 advanceframe(false, false);
7868
2/2
✓ Branch 0 taken 29891 times.
✓ Branch 1 taken 178717 times.
208608 if (replay_version_check(11))
7869 178717 load_control_state();
7870
7871
2/2
✓ Branch 0 taken 207636 times.
✓ Branch 1 taken 972 times.
208608 if(getInput(btnS, true, false, true)) //rSbtn
7872 972 done = true;
7873
7874
2/2
✓ Branch 0 taken 973 times.
✓ Branch 1 taken 207635 times.
417216 }
7875
2/2
✓ Branch 0 taken 972 times.
✓ Branch 1 taken 207636 times.
208608 while(!done && !Quit);
7876
7877 973 ViewingMap = false;
7878 973 destroy_bitmap(mappic);
7879 973 resume_all_sfx();
7880 973 }
7881
7882 1075 int32_t onViewMap()
7883 {
7884
4/6
✓ Branch 0 taken 1075 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1075 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 102 times.
✓ Branch 5 taken 973 times.
1075 if(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)
7885 {
7886 973 clear_to_color(framebuf,BLACK);
7887 973 textout_centre_ex(framebuf,font,"Drawing map...",128,108,WHITE,BLACK);
7888 973 advanceframe(true);
7889 973 ViewMap();
7890 973 }
7891
7892 1075 return D_O_K;
7893 }
7894
7895 35652535 bool isGrassType(int32_t type)
7896 {
7897
2/2
✓ Branch 0 taken 34995769 times.
✓ Branch 1 taken 656766 times.
35652535 switch(type)
7898 {
7899 case cTALLGRASS:
7900 case cTALLGRASSNEXT:
7901 case cTALLGRASSTOUCHY:
7902 656766 return true;
7903 }
7904
7905 34995769 return false;
7906 35652535 }
7907
7908 20813 bool isFlowersType(int32_t type)
7909 {
7910
2/2
✓ Branch 0 taken 16473 times.
✓ Branch 1 taken 4340 times.
20813 switch(type)
7911 {
7912 case cFLOWERS:
7913 case cFLOWERSTOUCHY:
7914 4340 return true;
7915 }
7916
7917 16473 return false;
7918 20813 }
7919
7920 bool isGenericType(int32_t type)
7921 {
7922 switch(type)
7923 {
7924 case cTRIGGERGENERIC:
7925 return true;
7926 }
7927
7928 return false;
7929 }
7930
7931 25953 bool isBushType(int32_t type)
7932 {
7933
2/2
✓ Branch 0 taken 20813 times.
✓ Branch 1 taken 5140 times.
25953 switch(type)
7934 {
7935 case cBUSH:
7936 case cBUSHNEXT:
7937 case cBUSHTOUCHY:
7938 case cBUSHNEXTTOUCHY:
7939
7940 5140 return true;
7941 }
7942
7943 20813 return false;
7944 25953 }
7945
7946 bool isSlashType(int32_t type)
7947 {
7948 switch(type)
7949 {
7950 case cSLASH:
7951 case cSLASHITEM:
7952 case cSLASHTOUCHY:
7953 case cSLASHITEMTOUCHY:
7954 case cSLASHNEXT:
7955 case cSLASHNEXTITEM:
7956 case cSLASHNEXTTOUCHY:
7957 case cSLASHNEXTITEMTOUCHY:
7958 return true;
7959 }
7960
7961 return false;
7962 }
7963
7964 15592 bool isCuttableNextType(int32_t type)
7965 {
7966
2/2
✓ Branch 0 taken 9788 times.
✓ Branch 1 taken 5804 times.
15592 switch(type)
7967 {
7968 case cSLASHNEXT:
7969 case cSLASHNEXTITEM:
7970 case cTALLGRASSNEXT:
7971 case cBUSHNEXT:
7972 case cSLASHNEXTTOUCHY:
7973 case cSLASHNEXTITEMTOUCHY:
7974 case cBUSHNEXTTOUCHY:
7975 5804 return true;
7976 }
7977
7978 9788 return false;
7979 15592 }
7980
7981 17443 bool isTouchyType(int32_t type)
7982 {
7983
2/2
✓ Branch 0 taken 5947 times.
✓ Branch 1 taken 11496 times.
17443 switch(type)
7984 {
7985 case cSLASHTOUCHY:
7986 case cSLASHITEMTOUCHY:
7987 case cBUSHTOUCHY:
7988 case cFLOWERSTOUCHY:
7989 case cTALLGRASSTOUCHY:
7990 case cSLASHNEXTTOUCHY:
7991 case cSLASHNEXTITEMTOUCHY:
7992 case cBUSHNEXTTOUCHY:
7993 11496 return true;
7994 }
7995
7996 5947 return false;
7997 17443 }
7998
7999 29034651 bool isCuttableType(int32_t type)
8000 {
8001
2/2
✓ Branch 0 taken 28619857 times.
✓ Branch 1 taken 414794 times.
29034651 switch(type)
8002 {
8003 case cSLASH:
8004 case cSLASHITEM:
8005 case cBUSH:
8006 case cFLOWERS:
8007 case cTALLGRASS:
8008 case cTALLGRASSNEXT:
8009 case cSLASHNEXT:
8010 case cSLASHNEXTITEM:
8011 case cBUSHNEXT:
8012
8013 case cSLASHTOUCHY:
8014 case cSLASHITEMTOUCHY:
8015 case cBUSHTOUCHY:
8016 case cFLOWERSTOUCHY:
8017 case cTALLGRASSTOUCHY:
8018 case cSLASHNEXTTOUCHY:
8019 case cSLASHNEXTITEMTOUCHY:
8020 case cBUSHNEXTTOUCHY:
8021 414794 return true;
8022 }
8023
8024 28619857 return false;
8025 29034651 }
8026
8027 17220 bool isCuttableItemType(int32_t type)
8028 {
8029
2/2
✓ Branch 0 taken 424 times.
✓ Branch 1 taken 16796 times.
17220 switch(type)
8030 {
8031 case cSLASHITEM:
8032 case cBUSH:
8033 case cFLOWERS:
8034 case cTALLGRASS:
8035 case cTALLGRASSNEXT:
8036 case cSLASHNEXTITEM:
8037 case cBUSHNEXT:
8038
8039 case cSLASHITEMTOUCHY:
8040 case cBUSHTOUCHY:
8041 case cFLOWERSTOUCHY:
8042 case cTALLGRASSTOUCHY:
8043 case cSLASHNEXTITEMTOUCHY:
8044 case cBUSHNEXTTOUCHY:
8045 16796 return true;
8046 }
8047
8048 424 return false;
8049 17220 }
8050
8051 66 bool is_push(mapscr* m, int32_t pos)
8052 {
8053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if(is_push_flag(m->sflag[pos]))
8054 return true;
8055 66 newcombo const& cmb = combobuf[m->data[pos]];
8056
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if(is_push_flag(cmb.flag))
8057 return true;
8058
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 52 times.
66 if(cmb.type == cPUSHBLOCK)
8059 14 return true;
8060
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
52 if(cmb.type == cSWITCHHOOK && (cmb.usrflags&cflag7))
8061 return true; //Counts as 'pushblock' flag
8062 52 return false;
8063 66 }
8064
8065 408 static std::map<int, screen_state_t> screen_states;
8066
8067 35756 std::map<int, screen_state_t>& get_screen_states()
8068 {
8069 35756 return screen_states;
8070 }
8071
8072 44016451 screen_state_t& get_screen_state(int screen)
8073 {
8074 44016451 return screen_states[screen];
8075 }
8076
8077 573 void clear_screen_states()
8078 {
8079 573 screen_states.clear();
8080 573 }
8081
8082 1422 void screen_item_set_state(int screen, ScreenItemState state)
8083 {
8084 1422 get_screen_state(screen).item_state = state;
8085 1422 }
8086
8087 36915 void mark_visited(int screen)
8088 {
8089
2/2
✓ Branch 0 taken 473 times.
✓ Branch 1 taken 36442 times.
36915 if (screen < 0x80)
8090 {
8091
2/2
✓ Branch 0 taken 24563 times.
✓ Branch 1 taken 11879 times.
36442 if(DMaps[cur_dmap].flags&dmfVIEWMAP)
8092 11879 game->maps[mapind(cur_map, screen)] |= mVISITED;
8093
8094 36442 markBmap(-1, screen);
8095 36442 }
8096 36915 }
8097